load->model('supplier_model'); $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'] = 'Siddharth : Supplier'; $this->loadViews("supplierListing", $this->global, NULL , NULL); } /** * This function is used to load the Supplier list */ function supplierListing() { $this->load->model('supplier_model'); $data['userRecords'] = $this->supplier_model->supplierListing(); $this->global['pageTitle'] = 'Siddharth Industries : Supplier Listing'; $this->loadViews("supplierListing", $this->global, $data, NULL); } /** * This function is used to load the add new supplier */ function addsupplier() { //$data['payment'] = $this->supplier_model->getpayment(); $data['payment'] = $this->supplier_model->getPaymentTerms(); //$data['users'] = $this->purchaseorder_model->getusers(); $this->global['pageTitle'] = 'siddharth : 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->input->post('id'); $query = $this->supplier_model->checkPAN($id ); $query = $query[0]['PAN']; print_r($query); } /* To Check the Pan Number is exists in the database or not for the selected Supplier */ function checkPanValidateSupplier() { $SupplierID = $this->input->post('SupplierID'); $PanNo = $this->input->post('panno'); // echo 'Sup'. $SupplierID ; $query = $this->supplier_model->checkPAN($PanNo,$SupplierID); if (count($query)> 0) { $this->form_validation->set_message('checkPanValidateSupplier', 'The Entered PAN Number is already exists in the Database.'); return false; } else { return true; } } /* To Check the Pan Number is exists in the database or not */ function checkPanValidate() { // alert('validation pan'); $PanNo = $this->input->post('panno'); $query = $this->supplier_model->checkPAN($PanNo); if (count($query)> 0) { $this->form_validation->set_message('checkPanValidate', 'The Entered PAN Number is already exists in the Database.'); return false; } else { return true; } } function CheckGST() { //alert('check validation GST'); $id = $this->input->post('id'); $query = $this->supplier_model->checkGST($id); $query = $query[0]['GSTNO']; print_r($query); } /* To Check the GST Number is exists in the database or not for the selected Supplier */ function checkGstValidateSupplier() { //alert(' gst validation GST'); $SupplierID = $this->input->post('SupplierID'); $GstNo = $this->input->post('GSTNo'); //echo 'Sup'. $SupplierID ; $query = $this->supplier_model->checkGST($GstNo,$SupplierID); if (count($query)> 0) { $this->form_validation->set_message('checkGstValidateSupplier', 'The Entered GST Number is already exists in the Database.'); return false; } else { return true; } } /* To Check the GST Number is exists in the database or not */ function checkGstValidate() { $GstNo = $this->input->post('GSTNo'); $query = $this->supplier_model->checkGST($GstNo); if (count($query)> 0) { $this->form_validation->set_message('checkGstValidate', 'The Entered GST Number is already exists in the Database.'); return false; } else { return true; } } /** * This function is used to add new Supplier to the system */ function addNewsupplier() { $this->form_validation->set_rules('SupplierName','Supplier Name','trim|required'); $this->form_validation->set_rules('Address','Address','trim|required|'); $this->form_validation->set_rules('ContactNumber','Contact Number','trim|required|max_length[13]'); $this->form_validation->set_rules('AlternateContactNumber','Alternate Contact Number','trim|max_length[13]'); $this->form_validation->set_rules('emailid','emailid', 'valid_email|max_length[128]|required'); $this->form_validation->set_rules('TIN','TIN','trim|required|max_length[11]'); $this->form_validation->set_rules('panno', 'panno', 'trim|required|max_length[10]');//|callback_checkPanValidate'); $this->form_validation->set_rules('GSTNo','GSTNo','trim|requried|max_length[15]|callback_checkGstValidate'); if($this->form_validation->run() == FALSE) { $this->addsupplier(); } else { $SupplierName = $this->input->post('SupplierName'); $Address = $this->input->post('Address'); $ContactNumber = $this->input->post('ContactNumber'); $AlternateContactNumber = $this->input->post('AlternateContactNumber'); $EmailAddress = $this->input->post('emailid'); $Exiseregistration = $this->input->post('Exciseregistration'); $TIN = $this->input->post('TIN'); $PAN = strtoupper($this->input->post('panno')); $GSTNo = strtoupper($this->input->post('GSTNo')); $GSTRange = $this->input->post('GSTRange'); $CollectrateAddress = $this->input->post('CollectrateAddress'); $UANumber = $this->input->post('UANumber'); //$PaymentTerms = $this->input->post('paymentname'); //$Payment = $this->input->post('Payment'); //$PayableAT = $this->input->post('PayableAT'); $CSTNo = $this->input->post('CSTNo'); $CSTDt = $this->input->post('dateofCST'); if($CSTDt != '') { $CSTDate = $this->getDateformat($CSTDt); } else { $CSTDate = null; } $EMSNo = $this->input->post('EMSNo'); $TSNo = $this->input->post('TSNo'); $IMSNo = $this->input->post('IMSNo'); $ISONo = $this->input->post('ISONo'); $OSHASNo = $this->input->post('OSHASNo'); $accno = $this->input->post('accno'); $ifsc = $this->input->post('ifsc'); $branchname = $this->input->post('branchname'); $bankaddress = $this->input->post('bankaddress'); $Createdby = $this->session->userdata ( 'userId' ); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $createddate = $date->format('Y-m-d H:i:s'); $service = $this->input->post('service'); $rawmaterial =$this->input->post('rawmaterial'); $maintenance = $this->input->post('maintanance'); $PaymentId = $this->input->post('paymentid'); $supplier = array('SupplierName'=>$SupplierName, 'Address'=>$Address, 'ContactNumber'=>$ContactNumber, 'AlternateContactNumber'=> $AlternateContactNumber,'EmailAddress'=>$EmailAddress,'Exiseregistration'=>$Exiseregistration,'TIN'=>$TIN,'PAN'=>$PAN,'GSTNo'=>$GSTNo,'GSTRange'=>$GSTRange,'CollectrateAddress'=>$CollectrateAddress,'UANumber'=>$UANumber,'PaymentID'=>$PaymentId,'CSTNo'=>$CSTNo,'CSTDate'=>$CSTDate,'CSTNo'=>$CSTNo,'CSTDate'=>$CSTDate,'Cert_EMS'=>$EMSNo, 'Cert_TS'=>$TSNo, 'Cert_IMS'=>$IMSNo, 'Cert_ISO'=>$ISONo, 'Cert_OSHAS'=>$OSHASNo, 'BankAcNumber'=>$accno, 'IFSCCode'=>$ifsc, 'BranchName'=>$branchname, 'BankAddress'=>$bankaddress,'Createdby'=>$Createdby,'IsService'=>$service,'IsMaintanance'=>$maintenance,'IsRawMaterial'=>$rawmaterial); //,'PaymentTerms'=>$PaymentTerms,'PaymentDays'=>$Payment,'PayableAT'=>$PayableAT); //print_r($supplier);die(); $result = $this->supplier_model->addNewsupplier($supplier); if($result > 0) { redirect('supplierListing','refresh'); echo ""; } else { redirect('supplierListing','refresh'); echo ""; } } } function getDateformat($Val) { $date = new DateTime($Val); $retDate = $date->format('Y-m-d H:i:s'); return $retDate; } /** * This function is used to edit the Supplier information */ function editsupplier() { $this->form_validation->set_rules('SupplierName','Supplier Name','trim|required'); $this->form_validation->set_rules('Address','Address','trim|required|'); $supplierID = $this->input->post('SupplierID'); //echo 'supID' . $supplierID ; $this->form_validation->set_rules('ContactNumber','Contact Number','trim|required|max_length[13]'); $this->form_validation->set_rules('AlternateContactNumber','Alternate Contact Number','trim|max_length[13]'); $this->form_validation->set_rules('emailid','emailid','valid_email|max_length[128]|required'); $this->form_validation->set_rules('TIN','TIN','trim|required|max_length[11]'); $this->form_validation->set_rules('panno', 'panno', 'trim|required|max_length[10]|callback_checkPanValidateSupplier'); $this->form_validation->set_rules('GSTNo','GSTNo','trim|requried|max_length[15]|callback_checkGstValidateSupplier'); if($this->form_validation->run() == FALSE) { $this->viewsupplier($supplierID); } else { $SupplierName = $this->input->post('SupplierName'); $Address = $this->input->post('Address'); $ContactNumber = $this->input->post('ContactNumber'); $AlternateContactNumber = $this->input->post('AlternateContactNumber'); $EmailAddress = $this->input->post('emailid'); $Exiseregistration = $this->input->post('Exciseregistration'); $TIN = $this->input->post('TIN'); $PAN = strtoupper($this->input->post('panno')); $GSTNo = strtoupper($this->input->post('GSTNo')); $GSTRange = $this->input->post('GSTRange'); $CollectrateAddress = $this->input->post('CollectrateAddress'); $UANumber = $this->input->post('UANumber'); $PaymentTerms = $this->input->post('paymentname'); //print_r($PaymentTerms); $UpdatedBy = $this->session->userdata ( 'userId' ); $chked = $this->input->post('isactive'); if( $chked != '') { $IsActive = '1'; } else { $IsActive = '0'; } $CSTNo = $this->input->post('CSTNo'); $CSTDt = $this->input->post('dateofCST'); if($CSTDt != '') { $CSTDate = $this->getDateformat($CSTDt); } else { $CSTDate = null; } $EMSNo = $this->input->post('EMSNo'); $TSNo = $this->input->post('TSNo'); $IMSNo = $this->input->post('IMSNo'); $ISONo = $this->input->post('ISONo'); $OSHASNo = $this->input->post('OSHASNo'); $accno = $this->input->post('accno'); $ifsc = $this->input->post('ifsc'); $branchname = $this->input->post('branchname'); $bankaddress = $this->input->post('bankaddress'); $service = $this->input->post('service'); $rawmaterial =$this->input->post('rawmaterial'); $maintanance = $this->input->post('maintanance'); $PaymentId = $this->input->post('paymentid'); $supplier = array(); $supplier = array('SupplierName'=>$SupplierName, 'Address'=>$Address, 'ContactNumber'=>$ContactNumber, 'AlternateContactNumber'=> $AlternateContactNumber,'EmailAddress'=>$EmailAddress,'Exiseregistration'=>$Exiseregistration,'TIN'=>$TIN,'PAN'=>$PAN,'GSTNo'=>$GSTNo,'GSTRange'=>$GSTRange,'CollectrateAddress'=>$CollectrateAddress,'UANumber'=>$UANumber,'PaymentID'=>$PaymentId,'CSTNo'=>$CSTNo,'CSTDate'=>$CSTDate,'Cert_EMS'=>$EMSNo, 'Cert_TS'=>$TSNo, 'Cert_IMS'=>$IMSNo, 'Cert_ISO'=>$ISONo, 'Cert_OSHAS'=>$OSHASNo, '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); // print_r($supplier);die(); $result = $this->supplier_model->UpdateSupplier($supplier, $supplierID); if($result == True) { redirect('supplierListing','refresh'); echo ""; } else { redirect('supplierListing','refresh'); echo ""; } } } 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'] = 'Siddharth : Edit Supplier'; $this->loadViews("editSupplier", $this->global,$data, NULL); } /** this function can be use for excel report **/ function export_supplierdetails(){ $this->load->library('excel'); $this->excel->setActiveSheetIndex(0); $this->excel->getActiveSheet()->setTitle('supplier details'); $this->excel->getActiveSheet()->setCellValue('A1', 'SupplierID'); $this->excel->getActiveSheet()->setCellValue('B1', 'SupplierName'); $this->excel->getActiveSheet()->setCellValue('C1', 'Address'); $this->excel->getActiveSheet()->setCellValue('D1', 'ContactNumber'); $this->excel->getActiveSheet()->setCellValue('E1', 'AlternateContactNumber'); $this->excel->getActiveSheet()->setCellValue('F1', 'EmailAddress'); $this->excel->getActiveSheet()->setCellValue('G1', 'Exiseregistration'); $this->excel->getActiveSheet()->setCellValue('H1', 'TIN'); $this->excel->getActiveSheet()->setCellValue('I1', 'PAN'); $this->excel->getActiveSheet()->setCellValue('J1', 'CSTNO'); $this->excel->getActiveSheet()->setCellValue('K1', 'CST Date'); $this->excel->getActiveSheet()->setCellValue('L1', 'GST NO'); $this->excel->getActiveSheet()->setCellValue('M1', 'GST Range'); $this->excel->getActiveSheet()->setCellValue('N1', 'Collectrate Address'); $this->excel->getActiveSheet()->setCellValue('O1', 'UANumber'); $this->excel->getActiveSheet()->setCellValue('P1', 'PaymentTerms'); $this->excel->getActiveSheet()->setCellValue('Q1', 'Createdby'); $this->excel->getActiveSheet()->setCellValue('R1', 'UpdatedBy'); $this->excel->getActiveSheet()->setCellValue('S1', 'IsActive'); $this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('B1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('C1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('D1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('D1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('E1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('E1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('F1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('F1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('G1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('G1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('H1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('H1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('I1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('I1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('J1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('J1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('K1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('K1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('L1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('L1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('M1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('M1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('N1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('N1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('O1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('O1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('P1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('P1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('Q1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('Q1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('R1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('R1')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('S1')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('S1')->getFont()->setBold(true); $exportData = $this->supplier_model->export_excel(); if ($exportData) { $i = 2; $s = 1; foreach ($exportData as $data) { $this->excel->getActiveSheet()->setCellValue('A' . $i,$data['SupplierID']); $this->excel->getActiveSheet()->setCellValue('B' . $i,$data['SupplierName']); $this->excel->getActiveSheet()->setCellValue('C' . $i,$data['Address']); $this->excel->getActiveSheet()->setCellValue('D' . $i,$data['ContactNumber']); $this->excel->getActiveSheet()->setCellValue('E' . $i,$data['AlternateContactNumber']); $this->excel->getActiveSheet()->setCellValue('F' . $i,$data['EmailAddress']); $this->excel->getActiveSheet()->setCellValue('G' . $i,$data['Exiseregistration']); $this->excel->getActiveSheet()->setCellValue('H' . $i,$data['TIN']); $this->excel->getActiveSheet()->setCellValue('I' . $i,$data['PAN']); $this->excel->getActiveSheet()->setCellValue('J' . $i,$data['CSTNO']); $this->excel->getActiveSheet()->setCellValue('K' . $i,$data['CSTDate']); $this->excel->getActiveSheet()->setCellValue('L' . $i,$data['GSTNO']); $this->excel->getActiveSheet()->setCellValue('M' . $i,$data['GSTRange']); $this->excel->getActiveSheet()->setCellValue('N' . $i,$data['CollectrateAddress']); $this->excel->getActiveSheet()->setCellValue('O' . $i,$data['UANumber']); $this->excel->getActiveSheet()->setCellValue('P' . $i,$data['PaymentTerms']); $this->excel->getActiveSheet()->setCellValue('Q' . $i,$data['firstname']); $this->excel->getActiveSheet()->setCellValue('R' . $i,$data['Update_by']); $this->excel->getActiveSheet()->setCellValue('S' . $i,$data['IsActive']); $i++; $s++; } } $filename = 'supplierdetails' .' '. '.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'] = 'Siddharth : 404 - Page Not Found'; $this->loadViews("404", $this->global, NULL, NULL); } } ?>