GIF89a; CRX
KBHT HEHE
Server IP : 172.26.0.195  /  Your IP : 3.15.228.32
Web Server : Apache
System : Linux 43-205-77-33.cprapid.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User : jnclnmuac ( 1026)
PHP Version : 8.0.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/jnclnmuac/public_html/web/pdf/../css/../../cas/application/controllers/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jnclnmuac/public_html/web/pdf/../css/../../cas/application/controllers/admin/Vendor.php
<?php

/**
 * Controller Class To Handle All Requests Related To Vehicles
 *
 * @author Softpro India Pvt. Ltd.
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class Vendor extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('admin/VendorManagement');
        $this->load->model('admin/LocationManagement');
    }

    public function index() {
        if ($this->sessionvalidator->isLoggedIn() && $this->sessionvalidator->isAccessGranted()) {
            $viewData['allVedors'] = $this->VendorManagement->getAllVendors()->result();
            $this->load->view('admin/vendors', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function createVendor() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['states'] = $this->LocationManagement->getAllNonDeletedStates()->result();
            $this->load->view('admin/createVendor', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function saveNewVendor() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $this->form_validation->set_rules('venOwnerName', 'Owner Name', 'trim|required', array('required' => 'Please Enter Owner Name.'));
            $this->form_validation->set_rules('venBusinessName', 'Business Name', 'trim|required', array('required' => 'Please Enter Business Name.'));
            $queryByBusinessName = $this->VendorManagement->getVendorInfoByBusinessName(trim($this->input->post('venBusinessName')));
            $vendorInfoByName = $queryByBusinessName->result();
            if ($this->form_validation->run() == FALSE) {
                $this->createVendor();
            } else if (sizeof($vendorInfoByName)) {
                $this->session->set_flashdata('errorMessage', "Another Firm With This Name (" . trim($this->input->post('venBusinessName')) . ") Already Exits. Please Choose Different Firm Name.");
                $this->createVendor();
            } else {
                $newVendorInfo = array(
                    'ven_business_name' => addslashes(trim($this->input->post('venBusinessName'))),
                    'ven_owner_name' => addslashes(trim($this->input->post('venOwnerName'))),
                    'ven_mobile' => trim($this->input->post('venMobile')),
                    'ven_email' => trim($this->input->post('venEmail')),
                    'ven_gstin_no' => trim($this->input->post('venGSTIN')),
                    'ven_pan' => trim($this->input->post('venPAN')),
                    'ven_alt_mobile' => (trim($this->input->post('venAltMobile')) == "") ? "" : trim($this->input->post('venAltMobile')),
                    'ven_alt_email' => (trim($this->input->post('venAltEmail')) == "") ? "" : trim($this->input->post('venAltEmail')),
                    'ven_website' => (trim($this->input->post('venWebsite')) == "") ? "" : trim($this->input->post('venWebsite')),
                    'ven_addr_line_one' => (trim($this->input->post('venAddrLineOne')) == "") ? "" : addslashes(trim($this->input->post('venAddrLineOne'))),
                    'ven_addr_line_two' => (trim($this->input->post('venAddrLineTwo')) == "") ? "" : addslashes(trim($this->input->post('venAddrLineTwo'))),
                    'ven_addr_line_three' => (trim($this->input->post('venAddrLineThree')) == "") ? "" : addslashes(trim($this->input->post('venAddrLineThree'))),
                    'ven_zipcode' => (trim($this->input->post('venZipcode')) == "") ? "" : trim($this->input->post('venZipcode')),
                    'state_id' => (trim($this->input->post('venState')) == "") ? "0" : trim($this->input->post('venState')),
                    'city_id' => (trim($this->input->post('venCity')) == "") ? "0" : trim($this->input->post('venCity')),
                    'ven_remarks' => (trim($this->input->post('venRemarks')) == "") ? "" : addslashes(trim($this->input->post('venRemarks'))),
                    'ven_source' => ($this->input->post('venSource') != "O") ? $this->input->post('venSource') : addslashes(trim($this->input->post('venOtherSource'))),
                    'ven_added_on' => date("Y-m-d H:i:s"),
                    'ven_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'ven_updated_on' => date("Y-m-d H:i:s"),
                    'ven_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->VendorManagement->createNewVendor($newVendorInfo)) {
                    $this->session->set_flashdata('successMessage', 'Vendor Added Successfully.');
                    redirect("admin/Vendor");
                } else {
                    $this->session->set_flashdata('errorMessage', "An Error Occured While Creating Vendor. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function editVendor($ven_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $viewData['states'] = $this->LocationManagement->getAllNonDeletedStates()->result();
            $viewData['vendor_info'] = $this->VendorManagement->getVendorInfoBy($ven_id)->result()[0];
            $this->load->view('admin/editVendor', $viewData);
        } else {
            redirect("admin/");
        }
    }

    public function updateVendor() {
        if ($this->sessionvalidator->isLoggedIn()) {
            $vendorId = $this->input->post('vendor_id');
            $this->form_validation->set_rules('venOwnerName', 'Owner Name', 'trim|required', array('required' => 'Please Enter Owner Name.'));
            $this->form_validation->set_rules('venBusinessName', 'Business Name', 'trim|required', array('required' => 'Please Enter Business Name.'));
            if ($this->form_validation->run() == FALSE) {
                $this->editVendor($vendorId);
            } else if (!$this->VendorManagement->isVendorBusinessNameSafeUpdate($vendorId, trim($this->input->post('venBusinessName')))) {
                $this->session->set_flashdata('errorMessage', "Another Firm With This Name (" . trim($this->input->post('venBusinessName')) . ") Already Exits. Please Choose Different Firm Name.");
                $this->editVendor($vendorId);
            } else {
                $vendorInfo = array(
                    'ven_id' => $vendorId,
                    'ven_business_name' => addslashes(trim($this->input->post('venBusinessName'))),
                    'ven_owner_name' => addslashes(trim($this->input->post('venOwnerName'))),
                    'ven_mobile' => trim($this->input->post('venMobile')),
                    'ven_email' => trim($this->input->post('venEmail')),
                    'ven_gstin_no' => trim($this->input->post('venGSTIN')),
                    'ven_pan' => trim($this->input->post('venPAN')),
                    'ven_alt_mobile' => (trim($this->input->post('venAltMobile')) == "") ? "" : trim($this->input->post('venAltMobile')),
                    'ven_alt_email' => (trim($this->input->post('venAltEmail')) == "") ? "" : trim($this->input->post('venAltEmail')),
                    'ven_website' => (trim($this->input->post('venWebsite')) == "") ? "" : trim($this->input->post('venWebsite')),
                    'ven_addr_line_one' => (trim($this->input->post('venAddrLineOne')) == "") ? "" : addslashes(trim($this->input->post('venAddrLineOne'))),
                    'ven_addr_line_two' => (trim($this->input->post('venAddrLineTwo')) == "") ? "" : addslashes(trim($this->input->post('venAddrLineTwo'))),
                    'ven_addr_line_three' => (trim($this->input->post('venAddrLineThree')) == "") ? "" : addslashes(trim($this->input->post('venAddrLineThree'))),
                    'ven_zipcode' => (trim($this->input->post('venZipcode')) == "") ? "" : trim($this->input->post('venZipcode')),
                    'state_id' => (trim($this->input->post('venState')) == "") ? "0" : trim($this->input->post('venState')),
                    'city_id' => (trim($this->input->post('venCity')) == "") ? "0" : trim($this->input->post('venCity')),
                    'ven_remarks' => (trim($this->input->post('venRemarks')) == "") ? "" : addslashes(trim($this->input->post('venRemarks'))),
                    'ven_source' => ($this->input->post('venSource') != "O") ? $this->input->post('venSource') : addslashes(trim($this->input->post('venOtherSource'))),
                    'ven_updated_on' => date("Y-m-d H:i:s"),
                    'ven_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                if ($this->VendorManagement->updateVendorInfo($vendorInfo)) {
                    $this->session->set_flashdata('successMessage', "Vendor Updated Successfully.");
                    redirect("admin/Vendor");
                } else {
                    $this->session->set_flashdata('errorMessage', "An Error Occured While Updating Vendor. Try Later.");
                    redirect(current_url());
                }
            }
        } else {
            redirect("admin/");
        }
    }

    public function toggleVendorStatus($ven_id, $toUpdateStatus) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $vendorUpdateData = array(
                'ven_id' => $ven_id,
                'ven_updated_on' => date("Y-m-d H:i:s"),
                'ven_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'ven_active_status' => $toUpdateStatus
            );
            if ($this->VendorManagement->updateVendorInfo($vendorUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Vendor Status Updated Successfully.');
                redirect("admin/Vendor");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Vendor Status. Try Later.');
                redirect("admin/Vendor");
            }
        } else {
            redirect("admin/");
        }
    }

    public function deleteVendor($ven_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $vendorUpdateData = array(
                'ven_id' => $ven_id,
                'ven_updated_on' => date("Y-m-d H:i:s"),
                'ven_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'ven_delete_status' => 'T'
            );
            if ($this->VendorManagement->updateVendorInfo($vendorUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Vendor Deleted Successfully.');
                redirect("admin/Vendor");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Deleting Vendor. Try Later.');
                redirect("admin/Vendor");
            }
        } else {
            redirect("admin/");
        }
    }

    public function undoDeleteVendor($ven_id) {
        if ($this->sessionvalidator->isLoggedIn()) {
            $vendorUpdateData = array(
                'ven_id' => $ven_id,
                'ven_updated_on' => date("Y-m-d H:i:s"),
                'ven_updated_by' => $this->session->userdata("adminData")["smember_id"],
                'ven_delete_status' => 'F'
            );
            if ($this->VendorManagement->updateVendorInfo($vendorUpdateData)) {
                $this->session->set_flashdata('successMessage', 'Vendor Recovered Successfully.');
                redirect("admin/Vendor");
            } else {
                $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Recovering Vendor. Try Later.');
                redirect("admin/Vendor");
            }
        } else {
            redirect("admin/");
        }
    }

    public function getVendorFullInfo() {
        $ven_id = $_POST['vendor_id'];
        $vendor_info = $this->VendorManagement->getVendorInfoBy($ven_id)->result()[0];
        $vendorAddress = ($vendor_info->ven_addr_line_one == "" || $vendor_info->ven_addr_line_one == NULL) ? "" : stripslashes($vendor_info->ven_addr_line_one);
        $vendorAddress .= ($vendor_info->ven_addr_line_two == "" || $vendor_info->ven_addr_line_two == NULL) ? "" : " " . stripslashes($vendor_info->ven_addr_line_two);
        $vendorAddress .= ($vendor_info->ven_addr_line_three == "" || $vendor_info->ven_addr_line_three == NULL) ? "" : " " . stripslashes($vendor_info->ven_addr_line_three);
        $vendorAddress .= ($vendor_info->ven_zipcode == "" || $vendor_info->ven_zipcode == NULL) ? "" : " " . stripslashes($vendor_info->ven_zipcode);
        if (trim($vendorAddress) == "") {
            $vendorAddress = "NA";
        }
        $responseData = array(
            'csrfName' => $this->security->get_csrf_token_name(),
            'csrfHash' => $this->security->get_csrf_hash(),
            'ven_id' => $vendor_info->ven_id,
            'ven_ownername' => stripslashes($vendor_info->ven_owner_name),
            'ven_business_name' => stripslashes($vendor_info->ven_business_name),
            'ven_mobile' => ($vendor_info->ven_mobile == "" || $vendor_info->ven_mobile == NULL) ? "NA" : $vendor_info->ven_mobile,
            'ven_email' => ($vendor_info->ven_email == "" || $vendor_info->ven_email == NULL) ? "NA" : $vendor_info->ven_email,
            'ven_gstin' => ($vendor_info->ven_gstin_no == "" || $vendor_info->ven_gstin_no == NULL) ? "NA" : $vendor_info->ven_gstin_no,
            'ven_pan' => ($vendor_info->ven_pan == "" || $vendor_info->ven_pan == NULL) ? "NA" : $vendor_info->ven_pan,
            'ven_alt_mobile' => ($vendor_info->ven_alt_mobile == "" || $vendor_info->ven_alt_mobile == NULL) ? "NA" : stripslashes($vendor_info->ven_alt_mobile),
            'ven_alt_email' => ($vendor_info->ven_alt_email == "" || $vendor_info->ven_alt_email == NULL) ? "NA" : stripslashes($vendor_info->ven_alt_email),
            'ven_website' => ($vendor_info->ven_website == "" || $vendor_info->ven_website == NULL) ? "NA" : $vendor_info->ven_website,
            'ven_address' => $vendorAddress,
            'ven_state' => ($vendor_info->state_id == "" || $vendor_info->state_id == NULL) ? "NA" : stripslashes($vendor_info->stateName),
            'ven_city' => ($vendor_info->city_id == "" || $vendor_info->city_id == NULL) ? "" : stripslashes($vendor_info->cityName),
            'ven_remarks' => ($vendor_info->ven_remarks == "" || $vendor_info->ven_remarks == NULL) ? "-" : stripslashes($vendor_info->ven_remarks),
            'ven_source' => ($vendor_info->ven_source == "" || $vendor_info->ven_source == NULL) ? "-" : stripslashes($vendor_info->ven_source),
            'ven_active_status' => ($vendor_info->ven_active_status == "T") ? "<i class='fa fa-check' style='color:#00FF00;'></i> Active" : "<i class='fa fa-ban' style='color:#FF0000;'></i> Disabled",
            'ven_delete_status' => ($vendor_info->ven_delete_status == "T") ? "<i class='fa fa-trash' style='color:#FF0000;'></i> Deleted" : "Not Deleted",
            'vev_added_by' => $vendor_info->addedByAdmin . " At " . date('d-m-Y h:i:s A', strtotime($vendor_info->ven_added_on)),
            'ven_updated_by' => $vendor_info->updatedByAdmin . " At " . date('d-m-Y h:i:s A', strtotime($vendor_info->ven_updated_on))
        );
        echo json_encode($responseData);
    }

    public function saveNewVendorAndReturnForDropDown() {
        if ($this->sessionvalidator->isLoggedIn()) {
            if (trim($this->input->post('venBusinessName')) == "" || trim($this->input->post('venOwnerName')) == "") {
                $responseData = array(
                    'csrfName' => $this->security->get_csrf_token_name(),
                    'csrfHash' => $this->security->get_csrf_hash(),
                    'ven_id' => -1,
                    'ven_ownername' => "",
                    'ven_business_name' => ""
                );
                echo json_encode($responseData);
            } else if (sizeof($this->VendorManagement->getVendorInfoByBusinessName(trim($this->input->post('venBusinessName')))->result())) {
                $responseData = array(
                    'csrfName' => $this->security->get_csrf_token_name(),
                    'csrfHash' => $this->security->get_csrf_hash(),
                    'ven_id' => 0,
                    'ven_ownername' => "",
                    'ven_business_name' => ""
                );
                echo json_encode($responseData);
            } else {
                $newVendorInfo = array(
                    'ven_business_name' => addslashes(trim($this->input->post('venBusinessName'))),
                    'ven_owner_name' => addslashes(trim($this->input->post('venOwnerName'))),
                    'ven_mobile' => trim($this->input->post('venMobile')),
                    'ven_email' => trim($this->input->post('venEmail')),
                    'ven_gstin_no' => trim($this->input->post('venGSTIN')),
                    'ven_pan' => trim($this->input->post('venPAN')),
                    'ven_alt_mobile' => (trim($this->input->post('venAltMobile')) == "") ? "" : trim($this->input->post('venAltMobile')),
                    'ven_alt_email' => (trim($this->input->post('venAltEmail')) == "") ? "" : trim($this->input->post('venAltEmail')),
                    'ven_website' => (trim($this->input->post('venWebsite')) == "") ? "" : trim($this->input->post('venWebsite')),
                    'ven_addr_line_one' => (trim($this->input->post('venAddrLineOne')) == "") ? "" : addslashes(trim($this->input->post('venAddrLineOne'))),
                    'ven_addr_line_two' => (trim($this->input->post('venAddrLineTwo')) == "") ? "" : addslashes(trim($this->input->post('venAddrLineTwo'))),
                    'ven_addr_line_three' => (trim($this->input->post('venAddrLineThree')) == "") ? "" : addslashes(trim($this->input->post('venAddrLineThree'))),
                    'ven_zipcode' => (trim($this->input->post('venZipcode')) == "") ? "" : trim($this->input->post('venZipcode')),
                    'state_id' => (trim($this->input->post('venState')) == "") ? "0" : trim($this->input->post('venState')),
                    'city_id' => (trim($this->input->post('venCity')) == "") ? "0" : trim($this->input->post('venCity')),
                    'ven_remarks' => (trim($this->input->post('venRemarks')) == "") ? "" : addslashes(trim($this->input->post('venRemarks'))),
                    'ven_source' => ($this->input->post('venSource') != "O") ? $this->input->post('venSource') : addslashes(trim($this->input->post('venOtherSource'))),
                    'ven_added_on' => date("Y-m-d H:i:s"),
                    'ven_added_by' => $this->session->userdata("adminData")["smember_id"],
                    'ven_updated_on' => date("Y-m-d H:i:s"),
                    'ven_updated_by' => $this->session->userdata("adminData")["smember_id"]
                );
                $vendor_id = $this->VendorManagement->createNewVendor($newVendorInfo);
                $vendor_info = $this->VendorManagement->getVendorInfoBy($vendor_id)->result()[0];
                $responseData = array(
                    'csrfName' => $this->security->get_csrf_token_name(),
                    'csrfHash' => $this->security->get_csrf_hash(),
                    'ven_id' => $vendor_info->ven_id,
                    'ven_ownername' => stripslashes($vendor_info->ven_owner_name),
                    'ven_business_name' => stripslashes($vendor_info->ven_business_name)
                );
                echo json_encode($responseData);
            }
        } else {
            redirect("admin/");
        }
    }

}

KBHT - 2023