ria/app/Controllers/Supplier.php
2024-05-06 03:47:37 +00:00

327 lines
14 KiB
PHP

<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use CodeIgniter\Validation\Exceptions\ValidationException;
use App\Models\Assetdetails_model;
use App\Models\Batchcard_model;
use App\Models\Cashbook_model;
use App\Models\Companydetails_model;
use App\Models\Config_model;
use App\Models\Costcenter_model;
use App\Models\Dashboard_Model;
use App\Models\Department_model;
use App\Models\Employeedetails_model;
use App\Models\Emppaydate_model;
use App\Models\Inwardgateregister_model;
use App\Models\Login_model;
use App\Models\Monthlypay_model;
use App\Models\Mrir_model;
use App\Models\Payroll_model;
use App\Models\Purchaseorder_model;
use App\Models\Quality_model;
use App\Models\Rawmaterialdetails_model;
use App\Models\Requistion_model;
use App\Models\Store_model;
use App\Models\Storerequistion_model;
use App\Models\Supplier_model;
use App\Models\User_model;
use App\Models\Zohobook_api_model;
/**
* 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->load->library('Excel');
$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 check whether PAN already exist or not
*/
function CheckPAN()
{
$id = $this->request->getPost('id');
$query = $this->supplier_model->checkPAN($id);
$response = ($query !== null && !empty($query)) ? $query[0]['PAN'] : null;
return $this->response->setJSON($response);
}
/* To Check the Pan Number is exists in the database or not */
public function checkPanValidate($PanNo)
{
$query = $this->supplier_model->checkPAN($PanNo);
if (count($query) > 0) {
return 'The Entered PAN Number is already exists in the Database.';
} else {
return true;
}
}
public function checkGST()
{
$id = $this->request->getPost('id');
$query = $this->supplier_model->checkGST($id);
$response = ($query !== null && !empty($query)) ? $query[0]['GSTNO'] : null;
return $this->response->setJSON($response);
}
/* To Check the GST Number is exists in the database or not */
public function checkGstValidate($GstNo)
{
$query = $this->supplier_model->checkGST($GstNo);
if (count($query) > 0) {
// $this->validator->setMessage('checkGstValidate', 'The Entered GST Number is already exists in the Database.');
// echo "<script>alert('The Entered GST Number is already exists in the Database.');</script>";
// return false;
return 'The Entered GST Number already exists in the Database.';
} else {
return true;
}
}
/**
* 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'
]
];
// $rules['panno'] = ($PAN=='') ? ['label' => 'panno','rules' => 'trim|max_length[10]']
// : ['label' => 'panno','rules' => 'trim|max_length[10]|checkPanValidate['.$PAN.']'];
// $rules['GSTNo'] = ($GSTNo=='') ? ['label' => 'GSTNo','rules' => 'trim|max_length[15]']
// : ['label' => 'GSTNo', 'rules' => 'trim|max_length[15]|checkGstValidate[' . $GSTNo . ']'];
$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 ;
$MSMENo = $this->request->getPost('MSMENo');
$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, 'Cert_MSME' => $MSMENo, 'BankAcNumber' => $accno, 'IFSCCode' => $ifsc, 'BranchName' => $branchname, 'BankAddress' => $bankaddress, 'Createdby' => $Createdby, 'IsService' => $service, 'IsMaintanance' => $maintenance, 'IsRawMaterial' => $rawmaterial); //,'PaymentTerms'=>$PaymentTerms,'PaymentDays'=>$Payment,'PayableAT'=>$PayableAT);
$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('MSMENo');
$PaymentTerms = $this->request->getPost('paymentname');
//print_r($PaymentTerms);
$UpdatedBy = $this->session->get('userId');
$chked = $this->request->getPost('isactive');
$IsActive = ($chked != '') ? '1' : '0';
$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, 'Cert_MSME' => $MSMENo, 'BankAcNumber' => $accno, 'IFSCCode' => $ifsc, 'BranchName' => $branchname, 'BankAddress' => $bankaddress, 'UpdatedBy' => $UpdatedBy, 'IsActive' => $IsActive, '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);
$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';
$this->loadViews("editSupplier", $this->global, $data, NULL);
}
function checksupplier()
{
$supp_name = $this->request->getPost('id');
$query = $this->supplier_model->checkSupplierExists($supp_name);
return $this->response->setJSON($query);
}
}