load->model('supplier_model'); $this->load->library('form_validation'); $this->load->library('pagination'); $this->load->library('Excel'); $this->isLoggedIn(); } /** * Index Page for this controller(default function of the class) */ public function index() { $this->global['pageTitle'] = 'Resico : Supplier'; //Load the view supplierListing.php $this->loadViews("supplierListing", $this->global, NULL , NULL); } /** * To load the Supplier list */ function supplierListing() { $this->load->model('supplier_model'); $data['userRecords'] = $this->supplier_model->supplierListing(); $this->global['pageTitle'] = 'Resico : Supplier Listing'; //Load the view supplierListing.php $this->loadViews("supplierListing", $this->global, $data, NULL); } /** * To load the add new supplier */ function addsupplier() { $data['payment'] = $this->supplier_model->getPaymentTerms(); $this->global['pageTitle'] = 'Resico : Add New Supplier'; //Load the view addsupplier.php $this->loadViews("addsupplier", $this->global,$data, NULL); } /** * 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'); $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() { $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; } } /** * To check whether GST Number already exist or not */ function CheckGST() { $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() { $SupplierID = $this->input->post('SupplierID'); $GstNo = $this->input->post('GSTNo'); $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; } } /** * To store supplier data into DB. */ function addNewsupplier() { $pan = $this->input->post('panno'); $gst = $this->input->post('GSTNo'); $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|max_length[11]'); if($pan=='') { $this->form_validation->set_rules('panno', 'panno', 'trim|max_length[10]'); } else { $this->form_validation->set_rules('panno', 'panno', 'trim|max_length[10]|callback_checkPanValidate'); } if($gst=='') { $this->form_validation->set_rules('GSTNo','GSTNo','trim|max_length[15]'); } else { $this->form_validation->set_rules('GSTNo','GSTNo','trim|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'); //$CSTNo = $this->input->post('CSTNo'); //$CSTDt = $this->input->post('dateofCST'); // if($CSTDt != '' ){ // if($CSTDt == '30/11/-0001'){ // $CSTDate = null; // } // else{ // $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('d-m-Y 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,'PAN'=>$PAN,'GSTNo'=>$GSTNo,'GSTRange'=>$GSTRange,'PaymentID'=>$PaymentId,'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); /*'UANumber'=>$UANumber,'CSTNo'=>$CSTNo,'CSTDate'=>$CSTDate,'CollectrateAddress'=>$CollectrateAddress,'Exiseregistration'=>$Exiseregistration,'TIN'=>$TIN,'PaymentTerms'=>$PaymentTerms,'PaymentDays'=>$Payment,'PayableAT'=>$PayableAT); */ $result = $this->supplier_model->addNewsupplier($supplier); if($result > 0) { echo ""; redirect('supplierListing','refresh'); } else { echo ""; redirect('supplierListing','refresh'); } } } /** * To Convert the dateformat (date with time) and stored into DB */ function getDateformat($Val) { $date = new DateTime($Val); $retDate = $date->format('Y-m-d H:i:s'); return $retDate; } /** * To Convert the dateformat (date only) and stored into DB */ function dateformat($DateValue) { $date = DateTime::createFromFormat('d/m/Y', $DateValue);//we should give the date as per DatePicker format. //if the date picker format is mismatched means it display as invalid date so that we can use this "IF" Conditions (i.e) If the above format returns false then the date is not formatted correctly if ($date === false) { return false; } $retDate = $date->format('Y-m-d'); //in this line using the parsed date., we can create a new formatting for storing value to datebase ("we choosing date value based on datepicker") return $retDate; } /** * To store edited Supplier information into DB */ function editsupplier() { $pan = $this->input->post('panno'); $gst = $this->input->post('GSTNo'); $this->form_validation->set_rules('SupplierName','Supplier Name','trim|required'); $this->form_validation->set_rules('Address','Address','trim|required|'); $supplierID = $this->input->post('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|max_length[11]'); if($pan=='') { $this->form_validation->set_rules('panno', 'panno', 'trim|max_length[10]'); } else { $this->form_validation->set_rules('panno', 'panno', 'trim|max_length[10]|callback_checkPanValidateSupplier'); } if($gst=='') { $this->form_validation->set_rules('GSTNo','GSTNo','trim|max_length[15]'); } else { $this->form_validation->set_rules('GSTNo','GSTNo','trim|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'); $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,'PAN'=>$PAN,'GSTNo'=>$GSTNo,'GSTRange'=>$GSTRange,'PaymentID'=>$PaymentId,'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); /**'Exiseregistration'=>$Exiseregistration,'TIN'=>$TIN,'CollectrateAddress'=>$CollectrateAddress,'UANumber'=>$UANumber,'CSTNo'=>$CSTNo,'CSTDate'=>$CSTDate, */ $result = $this->supplier_model->UpdateSupplier($supplier, $supplierID); if($result == True) { echo ""; redirect('supplierListing','refresh'); } else { echo ""; redirect('supplierListing','refresh'); } } } /** * To view the Supplier information and load's the edit supplier screen */ 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->getPaymentTerms($Payment); $this->global['pageTitle'] = 'Resico : Edit Supplier'; //Load the view editSupplier.php $this->loadViews("editSupplier", $this->global,$data, NULL); } /** * To Check and display the already existing supplier list */ function checksupplier() { $supp_name = $this->input->post('id'); $this->load->model('supplier_model'); $query = $this->supplier_model->checkSupplierExists($supp_name); echo json_encode($query); } /** * To export report of supplier details in excel */ function export_supplierdetails(){ $this->load->library('excel'); $this->excel->setActiveSheetIndex(0)->mergeCells('J3:R3'); $this->excel->setActiveSheetIndex(0)->getStyle('J3')->getAlignment()->applyFromArray(array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,)); $this->excel->getActiveSheet()->setTitle('Supplier details'); $this->excel->getActiveSheet()->setCellValue('J3', 'RESICO INDUSTRIES Supplier Details'); $this->excel->getActiveSheet()->setCellValue('A5', 'SupplierID'); $this->excel->getActiveSheet()->setCellValue('B5', 'SupplierName'); $this->excel->getActiveSheet()->setCellValue('C5', 'Address'); $this->excel->getActiveSheet()->setCellValue('D5', 'ContactNumber'); $this->excel->getActiveSheet()->setCellValue('E5', 'AlternateContactNumber'); $this->excel->getActiveSheet()->setCellValue('F5', 'EmailAddress'); //$this->excel->getActiveSheet()->setCellValue('G5', 'Exiseregistration'); //$this->excel->getActiveSheet()->setCellValue('H5', 'TIN'); $this->excel->getActiveSheet()->setCellValue('G5', 'PAN'); //$this->excel->getActiveSheet()->setCellValue('J5', 'CSTNO'); //$this->excel->getActiveSheet()->setCellValue('K5', 'CST Date'); $this->excel->getActiveSheet()->setCellValue('H5', 'GST NO'); $this->excel->getActiveSheet()->setCellValue('I5', 'GST Range'); //$this->excel->getActiveSheet()->setCellValue('N5', 'Collectrate Address'); $this->excel->getActiveSheet()->setCellValue('J5', 'UANumber'); $this->excel->getActiveSheet()->setCellValue('K5','EMS Number'); $this->excel->getActiveSheet()->setCellValue('L5','TS Number'); $this->excel->getActiveSheet()->setCellValue('M5','IMS Number'); $this->excel->getActiveSheet()->setCellValue('N5','ISO Number'); $this->excel->getActiveSheet()->setCellValue('O5','OHSAS Number'); $this->excel->getActiveSheet()->setCellValue('P5', 'BankStatemant'); $this->excel->getActiveSheet()->setCellValue('Q5', 'PaymentTerms'); $this->excel->getActiveSheet()->setCellValue('R5', 'IsService'); $this->excel->getActiveSheet()->setCellValue('S5', 'IsMaintanance'); $this->excel->getActiveSheet()->setCellValue('T5', 'IsRawMaterial'); $this->excel->getActiveSheet()->setCellValue('U5', 'Createdby'); $this->excel->getActiveSheet()->setCellValue('V5', 'UpdatedBy'); $this->excel->getActiveSheet()->setCellValue('W5', 'IsActive'); $this->excel->getActiveSheet()->getStyle('J3')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('J3')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('A5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('A5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('B5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('B5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('C5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('C5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('D5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('D5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('E5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('E5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('F5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('F5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('G5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('G5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('H5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('H5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('I5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('I5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('J5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('J5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('K5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('K5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('L5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('L5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('M5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('M5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('N5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('N5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('O5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('O5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('P5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('P5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('Q5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('Q5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('R5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('R5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('S5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('S5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('T5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('T5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('U5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('U5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('V5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('V5')->getFont()->setBold(true); $this->excel->getActiveSheet()->getStyle('W5')->getFont()->setSize(12); $this->excel->getActiveSheet()->getStyle('W5')->getFont()->setBold(true); // $this->excel->getActiveSheet()->getStyle('X5')->getFont()->setSize(12); // $this->excel->getActiveSheet()->getStyle('X5')->getFont()->setBold(true); // $this->excel->getActiveSheet()->getStyle('Y5')->getFont()->setSize(12); // $this->excel->getActiveSheet()->getStyle('Y5')->getFont()->setBold(true); // $this->excel->getActiveSheet()->getStyle('Z5')->getFont()->setSize(12); // $this->excel->getActiveSheet()->getStyle('Z5')->getFont()->setBold(true); // $this->excel->getActiveSheet()->getStyle('AA5')->getFont()->setSize(12); // $this->excel->getActiveSheet()->getStyle('AA5')->getFont()->setBold(true); // $this->excel->getActiveSheet()->getStyle('AB5')->getFont()->setSize(12); // $this->excel->getActiveSheet()->getStyle('AB5')->getFont()->setBold(true); $exportData = $this->supplier_model->export_excel(); if ($exportData) { $i = 6; $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['Cert_EMS']); $this->excel->getActiveSheet()->setCellValue('Q' . $i,$data['Cert_TS']); $this->excel->getActiveSheet()->setCellValue('R' . $i,$data['Cert_IMS']); $this->excel->getActiveSheet()->setCellValue('S' . $i,$data['Cert_ISO']); $this->excel->getActiveSheet()->setCellValue('T' . $i,$data['Cert_OSHAS']); $this->excel->getActiveSheet()->setCellValue('U' . $i,$data['BankAcNumber'].'-'.$data['IFSCCode'].'-'.$data['BranchName'].$data['BankAddress']); $this->excel->getActiveSheet()->setCellValue('V' . $i,$data['PaymentTerms']); $this->excel->getActiveSheet()->setCellValue('W' . $i,$data['IsService']); // $this->excel->getActiveSheet()->setCellValue('X' . $i,$data['IsMaintanance']); // $this->excel->getActiveSheet()->setCellValue('Y' . $i,$data['IsRawMaterial']); // $this->excel->getActiveSheet()->setCellValue('Z' . $i,$data['firstname']); // $this->excel->getActiveSheet()->setCellValue('AA' . $i,$data['Update_by']); // $this->excel->getActiveSheet()->setCellValue('AB' . $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'); } /** * To load pagenotfound view */ function pageNotFound() { $this->global['pageTitle'] = 'Resico : 404 - Page Not Found'; //Load the view 404.php $this->loadViews("404", $this->global, NULL, NULL); } } ?>