529 lines
21 KiB
PHP
Executable File
529 lines
21 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
|
|
use CodeIgniter\Validation\Exceptions\ValidationException;
|
|
|
|
use App\Models\Supplier_model;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
|
|
|
|
|
|
/**
|
|
* Module : Supplier
|
|
* Supplier Class to control all supplier related operations.
|
|
* @author : Gandhimathi
|
|
* @version : 1.1
|
|
* @since : 12 Apr 2017
|
|
* @example : Revised at 15th april 2024
|
|
*/
|
|
class Supplier extends BaseController
|
|
{
|
|
protected $supplier_model;
|
|
protected $session;
|
|
/**
|
|
* This is default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->supplier_model = new Supplier_model();
|
|
$this->session = session();
|
|
helper('form'); //$this->load->library('form_validation');
|
|
// $this->load->library('pagination');
|
|
$this->isLoggedIn();
|
|
|
|
}
|
|
|
|
/**
|
|
* This function is used to load the Supplier list
|
|
*/
|
|
public function index()
|
|
{
|
|
$data['userRecords'] = $this->supplier_model->supplierlisting();
|
|
$this->global['pageTitle'] = 'Supplier Listing';
|
|
$this->loadViews("supplierListing", $this->global, $data, NULL);
|
|
}
|
|
|
|
/**
|
|
* This function is used to load the add new supplier */
|
|
function addsupplier()
|
|
{
|
|
|
|
$data['validation'] = session()->getFlashdata('validation_errors');
|
|
|
|
//$data['payment'] = $this->supplier_model->getpayment();
|
|
$data['payment'] = $this->supplier_model->getPaymentTerms();
|
|
//$data['users'] = $this->purchaseorder_model->getusers();
|
|
|
|
$this->global['pageTitle'] = 'Add New Supplier';
|
|
|
|
$this->loadViews("addSupplier", $this->global, $data, NULL);
|
|
}
|
|
|
|
/**
|
|
* This function is used to add new Supplier to the system
|
|
*/
|
|
function savesupplierdetails()
|
|
{
|
|
|
|
$PAN = $this->request->getPost('panno');
|
|
$GSTNo = $this->request->getPost('GSTNo');
|
|
|
|
$validation = \Config\Services::validation();
|
|
|
|
$rules = [
|
|
'SupplierName' => [
|
|
'label' => 'Supplier Name',
|
|
'rules' => 'trim|required'
|
|
],
|
|
'Address' => [
|
|
'label' => 'Address',
|
|
'rules' => 'trim|required'
|
|
],
|
|
'ContactNumber' => [
|
|
'label' => 'Contact Number',
|
|
'rules' => 'trim|required|max_length[13]'
|
|
],
|
|
'AlternateContactNumber' => [
|
|
'label' => 'Alternate Contact Number',
|
|
'rules' => 'trim|max_length[13]'
|
|
],
|
|
'emailid' => [
|
|
'label' => 'Email',
|
|
'rules' => 'valid_email|max_length[128]|required'
|
|
]
|
|
];
|
|
|
|
$messages = [
|
|
'SupplierName' => [
|
|
'required' => 'Please enter a supplier name.'
|
|
],
|
|
'Address' => [
|
|
'required' => 'Please enter an address.'
|
|
],
|
|
'ContactNumber' => [
|
|
'required' => 'Please enter a contact number.',
|
|
'max_length' => 'The contact number cannot exceed {param} characters.'
|
|
],
|
|
'AlternateContactNumber' => [
|
|
'max_length' => 'The alternate contact number cannot exceed {param} characters.'
|
|
],
|
|
'emailid' => [
|
|
'required' => 'Please enter an email address.',
|
|
'valid_email' => 'Please enter a valid email address.',
|
|
'max_length' => 'The email address cannot exceed {param} characters.'
|
|
]
|
|
// 'panno' => [
|
|
// 'required' => 'Please enter an panno address.',
|
|
// 'max_length' => 'The panno cannot exceed {param} characters.'
|
|
// ]
|
|
];
|
|
|
|
$validation->setRules($rules, $messages);
|
|
|
|
|
|
if (!$validation->withRequest($this->request)->run()) {
|
|
// $data['validation'] = $validation->getErrors();
|
|
session()->setFlashdata('validation_errors', $validation->getErrors());
|
|
return redirect()->route('addsupplier');
|
|
} else {
|
|
$SupplierName = $this->request->getPost('SupplierName');
|
|
$Address = $this->request->getPost('Address');
|
|
$ContactNumber = $this->request->getPost('ContactNumber');
|
|
$AlternateContactNumber = $this->request->getPost('AlternateContactNumber');
|
|
$EmailAddress = $this->request->getPost('emailid');
|
|
$PAN = (is_string($PAN)) ? strtoupper($PAN) : null ;
|
|
$GSTNo = (is_string($GSTNo)) ? strtoupper($GSTNo) : null ;
|
|
$MSME = $this->request->getPost('MSME');
|
|
$accno = $this->request->getPost('accno');
|
|
$ifsc = $this->request->getPost('ifsc');
|
|
$branchname = $this->request->getPost('branchname');
|
|
$bankaddress = $this->request->getPost('bankaddress');
|
|
$Createdby = $this->session->get('userId');
|
|
|
|
$service = $this->request->getPost('service');
|
|
$rawmaterial = $this->request->getPost('rawmaterial');
|
|
$maintenance = $this->request->getPost('maintanance');
|
|
$PaymentId = $this->request->getPost('paymentid');
|
|
|
|
$supplier = array('SupplierName' => $SupplierName, 'Address' => $Address, 'ContactNumber' => $ContactNumber, 'AlternateContactNumber' => $AlternateContactNumber, 'EmailAddress' => $EmailAddress, 'PAN' => $PAN, 'GSTNo' => $GSTNo, 'PaymentID' => $PaymentId, 'MSME' => $MSME, 'BankAcNumber' => $accno, 'IFSCCode' => $ifsc, 'BranchName' => $branchname, 'BankAddress' => $bankaddress, 'Createdby' => $Createdby, 'IsService' => $service, 'IsMaintanance' => $maintenance, 'IsRawMaterial' => $rawmaterial); //,'PaymentTerms'=>$PaymentTerms,'PaymentDays'=>$Payment,'PayableAT'=>$PayableAT);
|
|
|
|
$file1 = $this->request->getFile('Cert_MSME');
|
|
$file2 = $this->request->getFile('Cert_GST');
|
|
$file3 = $this->request->getFile('Cert_BANK');
|
|
$path = ROOTPATH.'public/uploads/images/';
|
|
|
|
if ($file2 && $file2->isValid() && !$file2->hasMoved()) {
|
|
if(!is_dir($path)) { mkdir($path, 0777, true); }
|
|
$GST_DOC = $file2->getName();
|
|
$file2->move($path,$GST_DOC);
|
|
$supplier['Cert_GST'] = $GST_DOC;
|
|
}
|
|
else{
|
|
$supplier['Cert_GST'] = NULL;
|
|
}
|
|
|
|
if ($file1 && $file1->isValid() && !$file1->hasMoved()) {
|
|
if(!is_dir($path)) { mkdir($path, 0777, true); }
|
|
$MSME_DOC = $file1->getName();
|
|
$file1->move($path,$MSME_DOC);
|
|
$supplier['Cert_MSME'] = $MSME_DOC;
|
|
}
|
|
else{
|
|
$supplier['Cert_MSME'] = NULL;
|
|
}
|
|
|
|
if ($file3 && $file3->isValid() && !$file3->hasMoved()) {
|
|
if(!is_dir($path)) { mkdir($path, 0777, true); }
|
|
$BANK_DOC = $file3->getName();
|
|
$file3->move($path,$BANK_DOC);
|
|
$supplier['Cert_BANK'] = $BANK_DOC;
|
|
}
|
|
else{
|
|
$supplier['Cert_BANK'] = NULL;
|
|
}
|
|
$result = $this->supplier_model->addNewsupplier($supplier);
|
|
|
|
if ($result > 0) {
|
|
$this->session->setFlashdata('success', 'New Supplier Created successfully!');
|
|
// echo '<script>alert("New Supplier Created successfully!");</script>';
|
|
} else {
|
|
$this->session->setFlashdata('error', 'Supplier Record Not Created!');
|
|
// echo '<script>alert("Supplier Record Not Created!");</script>';
|
|
}
|
|
return redirect()->route('supplierlisting');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is used to edit the Supplier information
|
|
*/
|
|
public function updatesupplierdetails()
|
|
{
|
|
$SupplierID = $this->request->getPost('SupplierID');
|
|
$SupplierName = $this->request->getPost('SupplierName');
|
|
$Address = $this->request->getPost('Address');
|
|
$ContactNumber = $this->request->getPost('ContactNumber');
|
|
$AlternateContactNumber = $this->request->getPost('AlternateContactNumber');
|
|
$EmailAddress = $this->request->getPost('emailid');$PAN = $this->request->getPost('panno');
|
|
$PAN = (is_string($PAN)) ? strtoupper($PAN) : null ;
|
|
$GSTNo = $this->request->getPost('GSTNo');
|
|
$GSTNo = (is_string($GSTNo)) ? strtoupper($GSTNo) : null ;
|
|
$MSMENo = $this->request->getPost('MSME');
|
|
$PaymentTerms = $this->request->getPost('paymentname');
|
|
//print_r($PaymentTerms);
|
|
$UpdatedBy = $this->session->get('userId');
|
|
|
|
|
|
|
|
$accno = $this->request->getPost('accno');
|
|
$ifsc = $this->request->getPost('ifsc');
|
|
$branchname = $this->request->getPost('branchname');
|
|
$bankaddress = $this->request->getPost('bankaddress');
|
|
$service = $this->request->getPost('service');
|
|
$rawmaterial = $this->request->getPost('rawmaterial');
|
|
$maintanance = $this->request->getPost('maintanance');
|
|
$PaymentId = $this->request->getPost('paymentid');
|
|
|
|
$supplier = array();
|
|
$supplier = array('SupplierName' => $SupplierName, 'Address' => $Address, 'ContactNumber' => $ContactNumber, 'AlternateContactNumber' => $AlternateContactNumber, 'EmailAddress' => $EmailAddress, 'PaymentID' => $PaymentId, 'MSME' => $MSMENo, 'BankAcNumber' => $accno, 'IFSCCode' => $ifsc, 'BranchName' => $branchname, 'BankAddress' => $bankaddress, 'UpdatedBy' => $UpdatedBy, 'IsService' => $service, 'IsMaintanance' => $maintanance, 'IsRawMaterial' => $rawmaterial); //'PaymentTerms'=>$PaymentTerms,'PaymentDays'=>$Payment);
|
|
//SupplierID, SupplierName, Address, ContactNumber, AlternateContactNumber, EmailAddress, Exiseregistration, TIN, PAN, CSTNO, CSTDate, GSTNO, GSTRange, CollectrateAddress, UANumber, PaymentTerms, PaymentDays, PayableAT, Cert_EMS, Cert_TS, Cert_IMS, Cert_ISO, Cert_OSHAS, BankAcNumber, IFSCCode, BranchName, BankAddress, Createdby, UpdatedBy, Updatedon, CreatedOn, IsActive);
|
|
$file1 = $this->request->getFile('Cert_MSME');
|
|
$file2 = $this->request->getFile('Cert_GST');
|
|
$file3 = $this->request->getFile('Cert_BANK');
|
|
$path = ROOTPATH.'public/uploads/images/';
|
|
|
|
if($PAN){ $supplier['PAN'] = $PAN;}
|
|
if($GSTNo){ $supplier['GSTNO'] = $GSTNo;}
|
|
if ($file2 && $file2->isValid() && !$file2->hasMoved()) {
|
|
if(!is_dir($path)) { mkdir($path, 0777, true); }
|
|
$GST_DOC = $file2->getName();
|
|
$file2->move($path,$GST_DOC);
|
|
$supplier['Cert_GST'] = $GST_DOC;
|
|
}
|
|
else{
|
|
$supplier['Cert_GST'] = $this->request->getPost('hidden_Cert_GST') ? $this->request->getPost('hidden_Cert_GST') : NULL;
|
|
}
|
|
|
|
if ($file1 && $file1->isValid() && !$file1->hasMoved()) {
|
|
if(!is_dir($path)) { mkdir($path, 0777, true); }
|
|
$MSME_DOC = $file1->getName();
|
|
$file1->move($path,$MSME_DOC);
|
|
$supplier['Cert_MSME'] = $MSME_DOC;
|
|
}
|
|
else{
|
|
$supplier['Cert_MSME'] = $this->request->getPost('hidden_Cert_MSME') ? $this->request->getPost('hidden_Cert_MSME') : NULL;
|
|
}
|
|
|
|
if ($file3 && $file3->isValid() && !$file3->hasMoved()) {
|
|
if(!is_dir($path)) { mkdir($path, 0777, true); }
|
|
$BANK_DOC = $file3->getName();
|
|
$file3->move($path,$BANK_DOC);
|
|
$supplier['Cert_BANK'] = $BANK_DOC;
|
|
}
|
|
else{
|
|
$supplier['Cert_BANK'] = $this->request->getPost('hidden_Cert_BANK') ? $this->request->getPost('hidden_Cert_BANK') : NULL;
|
|
}
|
|
|
|
$result = $this->supplier_model->UpdateSupplier($supplier, $SupplierID);
|
|
|
|
if ($result == True) {
|
|
$this->session->setFlashdata('success', 'Supplier Updated successfully!');
|
|
// echo "<script>alert('Supplier updated successfully!');</script>";
|
|
} else {
|
|
$this->session->setFlashdata('error', 'Supplier Not Udated!');
|
|
// echo "<script>alert('Supplier Record Not updated!');</script>";
|
|
}
|
|
return redirect()->route('supplierlisting');
|
|
}
|
|
|
|
|
|
function viewsupplier($SID = ''){
|
|
$Payment = '';
|
|
if ($SID == '') {
|
|
$supplierID = $_GET['SID'];
|
|
$Payment = $_GET['Payment'];
|
|
} else {
|
|
|
|
$supplierID = $SID;
|
|
}
|
|
|
|
|
|
$data['supplier'] = $this->supplier_model->getSupplierInfo($supplierID);
|
|
//$data['payment'] = $this->supplier_model->getpayment($Payment );
|
|
$data['payment'] = $this->supplier_model->getPaymentTerms($Payment);
|
|
$this->global['pageTitle'] = 'Edit Supplier';
|
|
// print_r($data['supplier']);die;
|
|
$this->loadViews("editSupplier", $this->global, $data, NULL);
|
|
}
|
|
|
|
function checksupplier()
|
|
{
|
|
|
|
$supp_id = $this->request->getPost('supplierId') ?? '';
|
|
|
|
$supp_name = $this->request->getPost('supplierName');
|
|
|
|
$supp_name = str_replace(' ', '', $supp_name);
|
|
|
|
|
|
$query = $this->supplier_model->checkSupplierExists($supp_id , $supp_name);
|
|
|
|
|
|
return $this->response->setJSON($query);
|
|
|
|
}
|
|
|
|
|
|
function deletesupplier()
|
|
{
|
|
$Sid = $this->request->getPost('id');
|
|
|
|
$updatedDate = get_current_date_time();
|
|
|
|
$SupplierInfo = array('IsActive' => 0, 'updatedBy' => $this->session->get('userId'), 'Updatedon' => $updatedDate);
|
|
|
|
$result = $this->supplier_model->deleteSupplier($Sid, $SupplierInfo);
|
|
|
|
echo 'Succssfully deleted the Supplier ..!!';
|
|
}
|
|
|
|
|
|
function reActivateSupplier()
|
|
{
|
|
$Sid = $this->request->getPost('id');
|
|
|
|
$updatedDate = get_current_date_time();
|
|
|
|
$SupplierInfo = array('IsActive' => 1, 'updatedBy' => $this->session->get('userId'), 'Updatedon' => $updatedDate);
|
|
|
|
$result = $this->supplier_model->reActivateSupplier($Sid, $SupplierInfo);
|
|
|
|
echo 'Succssfully Re-activated the Supplier ..!!';
|
|
}
|
|
|
|
function exportsupplier()
|
|
{
|
|
|
|
$data = $this->supplier_model->export_excel();
|
|
$file_name = 'Supplierdetails.xls';
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->mergeCells('B3:P3');
|
|
$sheet->getStyle('B3')->getAlignment()->setHorizontal('center');
|
|
$sheet->setTitle('Supplier details');
|
|
|
|
$headers = [
|
|
'B3' => 'RESICO Supplier Details',
|
|
'A5' => 'SupplierID',
|
|
'B5' => 'SupplierName',
|
|
'C5' => 'Address',
|
|
'D5' => 'ContactNumber',
|
|
'E5' => 'AlternateContactNumber',
|
|
'F5' => 'EmailAddress',
|
|
'G5' => 'PAN',
|
|
'H5' => 'GST NO',
|
|
'I5' => 'MSME NO',
|
|
'J5' => 'BankStatemant',
|
|
'K5' => 'PaymentTerms',
|
|
'L5' => 'IsService',
|
|
'M5' => 'IsMaintanance',
|
|
'N5' => 'IsRawMaterial',
|
|
'O5' => 'CreatedBy',
|
|
'P5' => 'UpdatedBy',
|
|
'Q5' => 'IsActive'
|
|
];
|
|
|
|
foreach ($headers as $cell => $value) {
|
|
$sheet->setCellValue($cell, $value);
|
|
$sheet->getStyle($cell)->getFont()->setSize($cell == 'B3' ? 14 : 12);
|
|
$sheet->getStyle($cell)->getFont()->setBold(true);
|
|
}
|
|
|
|
if($data){
|
|
$row = 6; // Start from row 6
|
|
foreach ($data as $d) {
|
|
$col = 'A'; // Start from column A
|
|
foreach ($d as $value) {
|
|
$sheet->setCellValue($col . $row, $value);
|
|
$col++;
|
|
}
|
|
$row++;
|
|
}
|
|
}
|
|
// $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;
|
|
}
|
|
|
|
/**
|
|
* This function used to Transporter listing
|
|
*/
|
|
public function transporterListing()
|
|
{
|
|
$data['userRecords'] = $this->supplier_model->transporterListing();
|
|
$this->global['pageTitle'] = 'Transporter List';
|
|
$this->loadViews("transporterListing", $this->global, $data, NULL);
|
|
}
|
|
|
|
/**
|
|
* This function is used to add/edit Transporter
|
|
*/
|
|
public function fetchTransporterDetails() {
|
|
|
|
$id = $this->request->getPost('transporterid');
|
|
$name = $this->request->getPost('transportername');
|
|
$userId = $this->session->get('userId');
|
|
|
|
$data = ['status' => false, 'message' => 'An error occurred while creating transporter details'.gettype($id)];
|
|
|
|
$id = trim($id);
|
|
if ((int)$id === 0) {
|
|
$addarr = [
|
|
'name' => $name,
|
|
'created_by' => $userId,
|
|
];
|
|
if ($this->supplier_model->saveTransporter($addarr) > 0) {
|
|
$data = ['status' => true, 'message' => 'Successfully created transporter details'];
|
|
}
|
|
}else{
|
|
$editarr = ['name' => $name,'updated_by' => $userId];
|
|
if ($this->supplier_model->updateTransporter($editarr, (int)$id) > 0) {
|
|
$data = ['status' => true, 'message' => 'Successfully updated transporter details'];
|
|
}
|
|
}
|
|
|
|
|
|
return $this->response->setJSON($data);
|
|
}
|
|
|
|
|
|
/**
|
|
* check the Transporter exists?
|
|
*/
|
|
|
|
function checkTransporter(){
|
|
|
|
$data = $this->request->getPost();
|
|
$transporterId = $data['transporterid']??'';
|
|
$transporterName = $data['transportername'];
|
|
$transporterName = str_replace(' ', '', $transporterName);
|
|
$message = $this->supplier_model->checkTransporter($transporterId,$transporterName);
|
|
|
|
return $this->response->setJSON($message);
|
|
|
|
}
|
|
|
|
/**
|
|
* delete the Transporter
|
|
*/
|
|
function deleteTransporter($id = NULL)
|
|
{
|
|
|
|
$ID = $id ?? $_GET['id'];
|
|
if(!empty($ID)){
|
|
$updatedDate = get_current_date_time();
|
|
$SupplierInfo = array('isactive' => 0, 'updated_by' => $this->session->get('userId'), 'updated_on' => $updatedDate);
|
|
|
|
|
|
$message = $this->supplier_model->deleteTransporter($ID, $SupplierInfo);
|
|
}else{
|
|
$message = "Transporter ID Not Avalable";
|
|
}
|
|
$this->session->setFlashdata('success', $message);
|
|
return redirect()->route('transporterListing');
|
|
|
|
}
|
|
|
|
/**
|
|
* reactivate the Transporter
|
|
*/
|
|
function reActivateTransporter($id = NULL)
|
|
{
|
|
|
|
$ID = $id ?? $_GET['id'];
|
|
if(!empty($ID)){
|
|
$updatedDate = get_current_date_time();
|
|
$SupplierInfo = array('isactive' => 1, 'updated_by' => $this->session->get('userId'), 'updated_on' => $updatedDate);
|
|
|
|
$message = $this->supplier_model->reActivateTransporter($ID, $SupplierInfo);
|
|
}else{
|
|
$message = "Transporter ID Not Avalable";
|
|
}
|
|
$this->session->setFlashdata('success', $message);
|
|
return redirect()->route('transporterListing');
|
|
|
|
}
|
|
|
|
} |