442 lines
16 KiB
PHP
442 lines
16 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
|
|
use CodeIgniter\Validation\Exceptions\ValidationException;
|
|
|
|
use App\Models\Rawmaterialdetails_model;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
|
|
|
|
/**
|
|
* Module : Material Master details
|
|
* Rawmaterialdetails Class to control all Rawmaterialdetails related operations.
|
|
* @author : Gandhimathi
|
|
* @version : 1.1
|
|
* @since : 12 Apr 2017
|
|
* @example : Revised at 15th april 2024
|
|
*/
|
|
class Rawmaterialdetails extends BaseController
|
|
{
|
|
protected $rawmaterialdetails_model;
|
|
protected $session;
|
|
|
|
/**
|
|
* This is default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->rawmaterialdetails_model = new Rawmaterialdetails_model();;
|
|
$this->session = session();
|
|
helper('form'); //$this->load->library('form_validation');
|
|
// $this->load->library('pagination');
|
|
// $this->load->library('Excel');
|
|
|
|
$this->isLoggedIn();
|
|
|
|
}
|
|
|
|
/**
|
|
* This function used to load the first screen of the user
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->global['pageTitle'] = 'RawMaterialDetails';
|
|
|
|
$this->loadViews("rawmaterialListing", $this->global, NULL, NULL);
|
|
}
|
|
|
|
/**
|
|
* This function is used to load the RawMaterialDetails list
|
|
*/
|
|
function rawmaterialListing()
|
|
{
|
|
|
|
$this->rawmaterialdetails_model = new rawmaterialdetails_model();;
|
|
|
|
$data['userRecords'] = $this->rawmaterialdetails_model->rawmaterialListing();
|
|
|
|
$this->global['pageTitle'] = 'RawMaterial Listing';
|
|
|
|
$this->loadViews("rawmaterialListing", $this->global, $data, NULL);
|
|
}
|
|
|
|
|
|
function shortagematerialListing()
|
|
{
|
|
|
|
$this->rawmaterialdetails_model = new rawmaterialdetails_model();;
|
|
|
|
|
|
$data['Records'] = $this->rawmaterialdetails_model->reOrderListing();
|
|
$this->global['pageTitle'] = 'ReOrderLevel Listing';
|
|
|
|
$this->loadViews("shortagematerialListing", $this->global, $data, NULL);
|
|
}
|
|
|
|
/**
|
|
* This function is used to load the add new cost */
|
|
function addRawMaterial()
|
|
{
|
|
|
|
$this->rawmaterialdetails_model = new 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'] = '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->validator->setMessage('MaterialType_validate', 'Please Select Material Type.');
|
|
echo "<script>alert('Please Select Material Type.');</script>";
|
|
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->validator->setMessage('UOM_validate', 'Please Select UOM.');
|
|
echo "<script>alert('Please Select UOM.');</script>";
|
|
return false;
|
|
} else // user picked something
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/* Validation for Material Category Dropdown */
|
|
function materialcategory_validate($selectValue)
|
|
{
|
|
|
|
if ($selectValue == '0') {
|
|
// $this->validator->setMessage('materialcategory_validate', 'Please Select Material Category.');
|
|
echo "<script>alert('Please Select Material Category.');</script>";
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
function addNewRawMaterial()
|
|
{
|
|
|
|
//echo "HI";die();
|
|
$TempArr = [];
|
|
|
|
$MaterialName = $this->request->getPost('MaterialName');
|
|
$MaterialType = $this->request->getPost('MaterialType');
|
|
$UOM = $this->request->getPost('UOM');
|
|
$MaterialCategory = $this->request->getPost('MatCate');
|
|
$materialcategoryarray = $this->rawmaterialdetails_model->getmaterialCategory();
|
|
|
|
foreach ($materialcategoryarray as $mc) {
|
|
$TempArr[] = $mc->ConfigValue;
|
|
}
|
|
//print_r($TempArr);
|
|
if (in_array($MaterialCategory, $TempArr)) {
|
|
//echo "Match found";
|
|
} else {
|
|
//echo "Match not found";
|
|
$configcode = 'C023';
|
|
$config = array('Config_ID' => $configcode, 'ConfigValue' => $MaterialCategory);
|
|
$query = $this->rawmaterialdetails_model->insertvalueintoconfig($config);
|
|
}
|
|
$Remarks = $this->request->getPost('remarks');
|
|
$HSN = $this->request->getPost('HSNcode');
|
|
$CreatedBy = $this->session->get('userId');
|
|
$stock = $this->request->getPost('openstock');
|
|
$reorder = $this->request->getPost('reorder');
|
|
$stockdate = $this->request->getPost('Date');
|
|
|
|
$currentstock = '';
|
|
$today_dt = get_current_date();
|
|
|
|
if (empty($stockdate)) {
|
|
// $stockdate = NULL;
|
|
$stockdate = get_current_date();
|
|
$currentstock = $stock;
|
|
} else {
|
|
$stockdate = format_date($stockdate,0,"Y-m-d");
|
|
$todaydateyear = format_date($today_dt,0,"Y");
|
|
$openstockdateyear = format_date($stockdate,0,"Y");
|
|
$parts = explode('-', $stockdate);
|
|
$openstockdatemonth = $parts[1];
|
|
$openstockdatedate = $parts[2];
|
|
|
|
if ($openstockdateyear == $todaydateyear) {
|
|
if ($openstockdatemonth <= 03) {
|
|
$currentstock = 0;
|
|
} else {
|
|
$currentstock = $stock;
|
|
}
|
|
} else if ($openstockdateyear < $todaydateyear) {
|
|
//$total= $y;
|
|
$currentstock = 0;
|
|
} else if ($openstockdateyear > $todaydateyear) {
|
|
$currentstock = $stock;
|
|
}
|
|
}
|
|
|
|
$chked = $this->request->getPost('isactive');
|
|
$IsActive = ($chked != '') ? '1' : '0';
|
|
$HSNcode = ($HSN == '') ? null : $HSN;
|
|
|
|
|
|
$RawMaterial = array('MaterialName' => $MaterialName, 'MaterialType' => $MaterialType, 'UOM' => $UOM, 'Category' => $MaterialCategory, 'CreatedBy' => $CreatedBy, 'IsActive' => $IsActive, 'Remarks' => $Remarks, 'HSNCODE' => $HSNcode, 'stock' => $stock, 'stockdate' => $stockdate, 'reorder' => $reorder, 'Current_stock' => $currentstock);
|
|
//print_r($RawMaterial);die();
|
|
$result = $this->rawmaterialdetails_model->addNewRawMaterial($RawMaterial);
|
|
|
|
if ($result > 0) {
|
|
$this->session->setFlashdata('success', 'RawMaterial Created successfully!');
|
|
} else {
|
|
$this->session->setFlashdata('error', 'RawMaterial Not Created!');
|
|
}
|
|
return redirect()->route('rawmaterialListing');
|
|
|
|
}
|
|
|
|
function viewRawmaterial($RID = '')
|
|
{
|
|
$MaterialType = '';
|
|
$UOM = '';
|
|
$MaterialCategory = '';
|
|
|
|
|
|
if ($RID == '') {
|
|
$RawMaterialID = $_GET['RID'];
|
|
$MaterialType = $_GET['MType'];
|
|
$UOM = $_GET['UOM'];
|
|
$currentdate = $_GET['date1'];
|
|
} else {
|
|
$RawMaterialID = $RID;
|
|
}
|
|
|
|
$data['materialDetails'] = $this->rawmaterialdetails_model->getMaterialDetails($RawMaterialID);
|
|
$data['currentstock'] = $this->rawmaterialdetails_model->getMaterialstock($RawMaterialID, $currentdate);
|
|
$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();
|
|
$data['avg_price'] = $this->rawmaterialdetails_model->getMaterialAvg($RawMaterialID);
|
|
//print_r($data['avg_price']);die();
|
|
$this->global['pageTitle'] = 'Edit Material Master';
|
|
$this->loadViews("editRawmaterial", $this->global, $data, NULL);
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is used to edit the user information
|
|
*/
|
|
function editRawmaterial()
|
|
{
|
|
|
|
|
|
$RawmaterialID = $this->request->getPost('MaterialCode');
|
|
|
|
$MaterialCode = $this->request->getPost('MaterialCode');
|
|
$MaterialName = $this->request->getPost('MaterialName');
|
|
$MaterialType = $this->request->getPost('MaterialType');
|
|
$MaterialCategory = $this->request->getPost('MaterialCategory');
|
|
$materialcategoryarray = $this->rawmaterialdetails_model->getmaterialCategory();
|
|
|
|
foreach ($materialcategoryarray as $mc) {
|
|
$TempArr[] = $mc->ConfigValue;
|
|
}
|
|
//print_r($TempArr);
|
|
if (in_array($MaterialCategory, $TempArr)) {
|
|
//echo "Match found";
|
|
} else {
|
|
//echo "Match not found";
|
|
$configcode = 'C023';
|
|
$config = array('Config_ID' => $configcode, 'ConfigValue' => $MaterialCategory);
|
|
$query = $this->rawmaterialdetails_model->insertvalueintoconfig($config);
|
|
}
|
|
$UOM = $this->request->getPost('UOM');
|
|
$Remarks = $this->request->getPost('remarks');
|
|
$HSN = $this->request->getPost('HSNcode');
|
|
$UpdatedBy = $this->session->get('userId');
|
|
$stock = $this->request->getPost('openstock');
|
|
$reorder = $this->request->getPost('reorder');
|
|
$stockdate = $this->request->getPost('Date');
|
|
$stockdate = (empty($stockdate)) ? NULL : format_date($stockdate,0,"Y-m-d");
|
|
|
|
$chked = $this->request->getPost('isactive');
|
|
$IsActive = ($chked != '') ? '1' : '0';
|
|
$HSNcode = ($HSN == '') ? null : $HSN;
|
|
|
|
$RawMaterial = array();
|
|
$RawMaterial = array('MaterialName' => $MaterialName, 'MaterialType' => $MaterialType, 'UpdatedBy' => $UpdatedBy, 'UOM' => $UOM, 'IsActive' => $IsActive, 'Category' => $MaterialCategory, 'Remarks' => $Remarks, 'HSNCODE' => $HSNcode, 'stock' => $stock, 'stockdate' => $stockdate, 'reorder' => $reorder); //,'RMCode'=>$rmcode);
|
|
|
|
$result = $this->rawmaterialdetails_model->editRawmaterial($RawMaterial, $MaterialCode);
|
|
|
|
if ($result == true) {
|
|
$this->session->setFlashdata('success', 'RawMaterial Updated successfully!');
|
|
} else {
|
|
echo "<script>alert('RawMaterial Record Not updated!');</script>";
|
|
$this->session->setFlashdata('error', 'RawMaterial Record Not updated!');
|
|
}
|
|
return redirect()->route('rawmaterialListing');
|
|
|
|
|
|
}
|
|
function autocomplete()
|
|
{
|
|
|
|
|
|
$mc = $this->request->getGet('query');
|
|
//echo $mc;die;
|
|
$query = $this->rawmaterialdetails_model->checkMaterialCategory($mc);
|
|
|
|
echo json_encode($query);
|
|
// foreach($query->result() as $row):
|
|
// echo "<li id='$row->id'>".$row->Category."</li>";
|
|
// endforeach;
|
|
}
|
|
|
|
function insertvalueintoconfig()
|
|
{
|
|
|
|
$mc = $this->request->getPost('id');
|
|
$configcode = 'C023';
|
|
$config = array('Config_ID' => $configcode, 'ConfigValue' => $mc);
|
|
|
|
$query = $this->rawmaterialdetails_model->insertvalueintoconfig($config);
|
|
}
|
|
|
|
function checkmaterial()
|
|
{
|
|
|
|
$material = $this->request->getPost('id');
|
|
$this->rawmaterialdetails_model = new rawmaterialdetails_model();;
|
|
$query = $this->rawmaterialdetails_model->checkMaterialExists($material);
|
|
return $this->response->setJSON($query);
|
|
|
|
//if(!empty($material)){
|
|
// echo json_encode($query);
|
|
//}
|
|
}
|
|
|
|
function exportmaterial()
|
|
{
|
|
|
|
$exportData = $this->rawmaterialdetails_model->export_excel();
|
|
|
|
$file_name = 'MaterialMaster' .' '. '.xls'; //save our workbook as this file name
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->mergeCells('F3:M3');
|
|
$sheet->getStyle('F3')->getAlignment()->setHorizontal('center');
|
|
$sheet->setTitle('Material Master');
|
|
|
|
$headers = [
|
|
'F3'=>'RESICO Material Master',
|
|
'C5'=>'MaterialCode',
|
|
'D5'=>'MaterialName',
|
|
'E5'=>'MaterialType',
|
|
'F5'=>'UOM',
|
|
'G5'=>'RMCode',
|
|
'H5'=>'Category',
|
|
'I5'=>'assetcode',
|
|
'J5'=>'CostCenterCode',
|
|
'K5'=>'ConversionFactorUnit',
|
|
'L5'=>'ConversionFactorUOM',
|
|
'M5'=>'HSNCode',
|
|
'N5'=>'Remarks',
|
|
'O5'=>'Created by',
|
|
'P5'=>'Updated By',
|
|
'Q5'=>'IsActive'
|
|
];
|
|
|
|
foreach ($headers as $cell => $value) {
|
|
$sheet->setCellValue($cell, $value);
|
|
$sheet->getStyle($cell)->getFont()->setSize($cell == 'F3' ? 14 : 12);
|
|
$sheet->getStyle($cell)->getFont()->setBold(true);
|
|
}
|
|
|
|
if($exportData){
|
|
$i = 6;$s = 1;
|
|
foreach ($exportData as $data) {
|
|
$rowData = [
|
|
'C' . $i=>$data['MaterialCode'],
|
|
'D' . $i=>$data['MaterialName'],
|
|
'E' . $i=>$data['MaterialType'],
|
|
'F' . $i=>$data['UOM'],
|
|
'G' . $i=>$data['RMCode'],
|
|
'H' . $i=>$data['Category'],
|
|
'I' . $i=>$data['assetcode'],
|
|
'J' . $i=>$data['CostCenterCode'],
|
|
'K' . $i=>$data['ConversionFactorUnit'],
|
|
'L' . $i=>$data['ConversionFactorUOM'],
|
|
'M' . $i=>$data['HSNCODE'],
|
|
'N' . $i=>$data['Remarks'],
|
|
'O' . $i=>$data['firstname'],
|
|
'P' . $i=>$data['Updated_By'],
|
|
'Q' . $i=>$data['IsActive']
|
|
];
|
|
|
|
foreach ($rowData as $cell => $value) {
|
|
$sheet->setCellValue($cell, $value);
|
|
}
|
|
|
|
$i++;
|
|
$s++;
|
|
}
|
|
|
|
}
|
|
// $writer = new Xlsx($spreadsheet);
|
|
// $writer->save($file_name);
|
|
// header("Content-Type: application/vnd.ms-excel");
|
|
// header('Content-Disposition: attachment; filename="' . basename($file_name) . '"');
|
|
// header('Expires: 0');
|
|
// header('Cache-Control: must-revalidate');
|
|
// header('Pragma: public');
|
|
// header('Content-Length:' . filesize($file_name));
|
|
// flush();
|
|
// readfile($file_name);
|
|
// exit;
|
|
// Clear the output buffer to prevent any other output
|
|
ob_clean();
|
|
|
|
$writer = new Xlsx($spreadsheet);
|
|
|
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
header('Content-Disposition: attachment;filename="'. $file_name .'"');
|
|
header('Cache-Control: max-age=0');
|
|
header('Expires: 0');
|
|
header('Pragma: public');
|
|
|
|
$writer->save('php://output');
|
|
exit;
|
|
}
|
|
|
|
|
|
}
|
|
|