diff --git a/api/application/config/routes.php b/api/application/config/routes.php index c2c7e0d1..18e306aa 100755 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -373,5 +373,11 @@ $route['deleteCalenderEvent'] = 'PD_Controller/deleteCalenderEvent'; //only deve $route['getSalesPDReportforCETApp'] = 'Sales_PD_Controller/getSalesPDReportforCETApp'; $route['getCreditPDReportforCETApp'] = 'SMC_Credit_PD_Controller/getCreditPDReportforCETApp'; -// $route['faceMarkImage'] = 'PD_Controller/toMakeFaceBoundingBox'; +$route['faceMarkImage'] = 'PD_Controller/toMakeFaceBoundingBox'; + +$route['saveFlyhiPD'] = 'Flyhi_Controller/saveFlyhiPD'; +$route['listFlyhiPD'] = 'Flyhi_Controller/listFlyhiPD'; +$route['listFlyhiSalesPD'] = 'Flyhi_Controller/listFlyhiPD'; +$route['getFlyhiPD'] = 'Flyhi_Controller/getFlyhiPD'; + diff --git a/api/application/controllers/Flyhi_Controller.php b/api/application/controllers/Flyhi_Controller.php new file mode 100644 index 00000000..a79f6ad7 --- /dev/null +++ b/api/application/controllers/Flyhi_Controller.php @@ -0,0 +1,288 @@ +load->model('Flyhi_Model','Flyhi_Model'); + $this->load->model('Sales_PD_Model','Sales_PD_Model'); + } + + public function listFlyhiPD_get(){ + + $user_id = $this->uri->segment(1); + + $columns = array('SALES_PD_DATA.sales_pd_id','SALES_PD_DATA.sales_pd_sno','SALES_PD_DATA.applicant_name','concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as officer_name','SALES_PD_DATA.applicant_id','SALES_PD_DATA.lender_id','SALES_PD_DATA.is_pdf','SALES_PD_DATA.is_edited','ENTITY.full_name','ENTITY.short_name','SALES_PD_DATA.status','SALES_PD_DATA.sales_pd_type','SALES_PD_DATA.rand_string','SALES_PD_DATA.isactive','SALES_PD_DATA.city_id','CITY.name as city_name', + 'SALES_PD_DATA.lender_sales_person','concat(LENDERSALESPERSON.first_name," ",LENDERSALESPERSON.last_name) as lender_sales_person_name','LENDERSALESPERSON.mobile_no as lender_sales_contact_mobileno','LENDERSALESPERSON.email as lender_sales_person_email', + 'SALES_PD_DATA.lender_credit_person','concat(LENDERCREDITPERSON.first_name," ",LENDERCREDITPERSON.last_name) as lender_credit_person_name','LENDERCREDITPERSON.mobile_no as lender_credit_person_contact_mobileno','LENDERCREDITPERSON.email as lender_credit_person_email', + 'SALES_PD_DATA.pd_branch_id,ENTITYLENDERBRANCH.branch_name','SALES_PD_DATA.loan_amount', + '(CASE WHEN SALES_PD_DATA.status = "STARTED" THEN SALES_PD_DATA.createdon WHEN SALES_PD_DATA.status = "COMPLETED" THEN SALES_PD_DATA.completed_date ELSE NULL END) AS createdon'); + $table = SALES_PD_DATA.' as SALES_PD_DATA'; + + $joins = array( + array('table' => ENTITY. ' as ENTITY', + 'condition' =>'SALES_PD_DATA.lender_id = ENTITY.entity_id', + 'jointype' => 'INNER'), + array('table' => CITY. ' as CITY', + 'condition' =>'SALES_PD_DATA.city_id = CITY.city_id', + 'jointype' => 'LEFT'), + array('table' => USERPROFILE. ' as USERPROFILE', + 'condition' =>'SALES_PD_DATA.createdby = USERPROFILE.userid', + 'jointype' => 'LEFT'), + array('table' => USERPROFILE. ' as LENDERSALESPERSON', + 'condition' =>'SALES_PD_DATA.lender_sales_person = LENDERSALESPERSON.userid', + 'jointype' => 'LEFT'), + array('table' => USERPROFILE. ' as LENDERCREDITPERSON', + 'condition' =>'SALES_PD_DATA.lender_credit_person = LENDERCREDITPERSON.userid', + 'jointype' => 'LEFT'), + array('table' => ENTITYLENDERBRANCH. ' as ENTITYLENDERBRANCH', + 'condition' =>'SALES_PD_DATA.pd_branch_id = ENTITYLENDERBRANCH.entity_lender_branch_id', + 'jointype' => 'LEFT') + ); + + $or_where = array(); + $where_condition_array['SALES_PD_DATA.isactive'] = 1; + + // FILTERING THE LAST 10 DAYS RECORDS + $key_date='SALES_PD_DATA.createdon BETWEEN DATE_SUB(NOW(), INTERVAL 60 DAY) AND NOW()'; + $condition_value=null; + $where_condition_array[$key_date] = $condition_value; + // ----END OF FILTERING THE LAST 10 DAYS RECORDS--- + + $FHFSL_lender = (ENVIRONMENT == 'production' ? 0 : 49); + if($user_id && is_numeric($user_id)) + { $where_condition_array['SALES_PD_DATA.createdby'] = $user_id; } + + $where_condition_array['SALES_PD_DATA.sales_pd_type in (3,4)'] = null; + $order_by = 'SALES_PD_DATA.sales_pd_id'; + + $Flyhi_pd_data = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC','',$or_where); + //print_r($this->db->last_query());die(); + + if(count($Flyhi_pd_data)) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $Flyhi_pd_data; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'FlyHI PD Data Not Found! Try Later'; + $this->response($data,REST_Controller::HTTP_OK); + } + } + + public function saveFlyhiPD_post() + { + $records = $this->post('records'); + $is_entry_done = null; + $flyhi_pd_id = null; + $section_data = json_encode($records); + $fk_createdby = $records['fk_createdby']; + $applicant_id = null; + $applicant_name = null; + $city = null; + $lender_id = null; + $loan_amount = null; + $pd_branch_id = null; + $lender_sales_person = null; + $lender_credit_person = null; + + log_message('ERROR','####FLYHI-PD SAVE CALLED'); + + // $section_names = array('1' => 'General Section','2' => 'Photography'); + $section_names = array('1' => 'General Section'); + + if($records['sales_pd_id'] == '' || $records['sales_pd_id'] == null) + { + + /************ASSIGN Random URL******************/ + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < 16; $i++) + { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + + $records['rand_string'] = $randomString; + log_message('ERROR','####INSERT NEW FLYHIPD'); + if($records['questions']) + { + foreach ($records['questions'] as $g_key => $g_value) + { + if($g_value['question_key'] == 'application_id') + { + $applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided'; + } + if($g_value['question_key'] == 'company_name') + { + $applicant_name = $g_value['answer_value']; + } + if($g_value['question_key'] == 'city') + { + $city = $g_value['answer_value']; + } + if($g_value['question_key'] == 'lender_id') + { + $lender_id = $g_value['answer_value']; + } + if($g_value['question_key'] == 'loan_amount') + { + $loan_amount = $g_value['answer_value']; + } + if($g_value['question_key'] == 'pd_branch_id') + { + $pd_branch_id = $g_value['answer_value']; + } + if($g_value['question_key'] == 'lender_sales_person') + { + $lender_sales_person = $g_value['answer_value']; + } + if($g_value['question_key'] == 'lender_credit_person') + { + $lender_credit_person = $g_value['answer_value']; + } + + } + } + $count = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $lender_id,'isactive' => 1),SALES_PD_DATA); + $lender_short_name = $this->Flyhi_Model->selectCustomRecords(array('short_name'),array('entity_id' => $lender_id),ENTITY); + $flyhipd_serial_no = $lender_short_name.'-'.(++$count[0]['count']); + $FLYHI_PD['applicant_name'] = $applicant_name; + $FLYHI_PD['applicant_id'] = $applicant_id; + $FLYHI_PD['city_id']=$city; + $FLYHI_PD['sales_pd_sno'] = $flyhipd_serial_no; + $FLYHI_PD['loan_amount'] = $loan_amount; + $FLYHI_PD['lender_sales_person'] = $lender_sales_person ; + $FLYHI_PD['lender_credit_person'] = $lender_credit_person ; + $FLYHI_PD['pd_branch_id'] = $pd_branch_id; + $FLYHI_PD['lender_id'] = $lender_id; + $FLYHI_PD['createdby'] = $fk_createdby; + $FLYHI_PD['rand_string'] = $randomString; + $flyhi_pd_id = $this->Flyhi_Model->saveRecords($FLYHI_PD,SALES_PD_DATA); + $section_data = json_encode($records); + $this->Sales_PD_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('sales_pd_id' =>$flyhi_pd_id,'section_id' => 1 )); + $status = $records['is_complete']; + $fields = array('sales_pd_id' => $flyhi_pd_id, 'section_id' => 1, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); + $is_entry_done = $this->Sales_PD_Model->saveRecords($fields,SALESPD_SECTION_DATA); + } + + else + { + if(isset($records['status']) && $records['status'] == 'COMPLETED') + { + log_message('ERROR','####COMPLETE FLYHI-PD'.$records['sales_pd_id']); + $records['status'] = 'COMPLETED'; + $records['is_cus_link_disabled'] = 1; + $records['completed_date'] = date('Y-m-d H:i:s'); + $flyhi_pd_id = $this->Flyhi_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id'])); + $completed_sections = $this->Flyhi_Model->selectCustomRecords(array('section_id'),array('status' => 1,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA); + } + else + { + + log_message('ERROR','####UPDATE FLYHIPD'.$records['sales_pd_id']); + // $gen_form = json_decode($form[0]['section_data'],true); + $flyhi_pd_id = $records['sales_pd_id']; + + if($records['questions']){ + foreach ($records['questions'] as $g_key => $g_value) + { + if($g_value['question_key'] == 'application_id') + { + $applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided'; + } + if($g_value['question_key'] == 'company_name') + { + $applicant_name = $g_value['answer_value']; + } + if($g_value['question_key'] == 'city') + { + $city = $g_value['answer_value']; + } + if($g_value['question_key'] == 'lender_id') + { + $lender_id = $g_value['answer_value']; + } + if($g_value['question_key'] == 'loan_amount') + { + $loan_amount = $g_value['answer_value']; + } + if($g_value['question_key'] == 'pd_branch_id') + { + $pd_branch_id = $g_value['answer_value']; + } + if($g_value['question_key'] == 'lender_sales_person') + { + $lender_sales_person = $g_value['answer_value']; + } + if($g_value['question_key'] == 'lender_credit_person') + { + $lender_credit_person = $g_value['answer_value']; + } + } + } + $FLYHI_PD['applicant_name'] = $applicant_name; + $FLYHI_PD['applicant_id'] = $applicant_id; + $FLYHI_PD['city_id']=$city; + $FLYHI_PD['loan_amount'] = $loan_amount; + $FLYHI_PD['lender_sales_person'] = $lender_sales_person ; + $FLYHI_PD['lender_credit_person'] = $lender_credit_person ; + $FLYHI_PD['pd_branch_id'] = $pd_branch_id; + $FLYHI_PD['lender_id'] = $lender_id; + $flyhi_pd_id = $this->Flyhi_Model->updateRecords($FLYHI_PD,SALES_PD_DATA,array('sales_pd_id' => $flyhi_pd_id)); + $status = $records['is_complete']; + $fields = array('sales_pd_id' => $flyhi_pd_id, 'section_id' => 1, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); + $is_entry_done = $this->Sales_PD_Model->saveRecords($fields,SALESPD_SECTION_DATA); + } // else 179 + } // else 167 + if($flyhi_pd_id) + { + $data['dataStatus'] = true; + $data['records'] = $flyhi_pd_id; + $data['status'] = REST_Controller::HTTP_OK; + if(isset($records['rand_string'])){ $data['rand_string'] = $records['rand_string']; } + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Something went wrong! Try Later'; + $this->response($data,REST_Controller::HTTP_OK); + } + } + + public function getFlyhiPD_get() + { + $Flyhi_pdid = $this->get('pd_id'); + $section_data = array(); + if(isset($Flyhi_pdid) || $Flyhi_pdid != "" || $Flyhi_pdid != null) + { + $section_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $Flyhi_pdid,'isactive' => 1,'section_id' => 1),SALESPD_SECTION_DATA); + } + if($section_data) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $section_data; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'No Data Found'; + $this->response($data,REST_Controller::HTTP_OK); + } + } +}// Class Ends diff --git a/api/application/controllers/PD_Controller.php b/api/application/controllers/PD_Controller.php index d16e7f80..224505e1 100644 --- a/api/application/controllers/PD_Controller.php +++ b/api/application/controllers/PD_Controller.php @@ -980,7 +980,7 @@ class PD_Controller extends REST_Controller { // SMS_GUPSHUP::sendSMS($msg,$no,array('pd_id' => $exist_pd_details[0]['pd_id'],'status' => 'STARTED','msg' => 'Cus Link from PD controlller')); // } - } + }// started if condition closed here. // die(); if(isset($pd_details['pd_status']) && (($pd_details['pd_status'] == COMPLETED) || ($pd_details['pd_status'] == ADD_ON_PENDING)) ) { @@ -989,6 +989,7 @@ class PD_Controller extends REST_Controller { { $pd_details['complete_override_data'] = json_encode($pd_details['complete_override_data']); $pd_details['completed_on'] = date('Y-m-d H:i:s'); + log_message('ERROR',"In PD Controller @ line no : 992 (When Completed status means calling to Make FaceBoundingBox fns below"); $this->toMakeFaceBoundingBox($exist_pd_details); } @@ -11947,10 +11948,12 @@ public function getCompaniesListsFromGeneralFormRawJSONV2_post() public function toMakeFaceBoundingBox($master_details){ // $pdid = $this->get('pd');//pdid 3184 comment this $pdid = $master_details[0]['pd_id']; + log_message('ERROR',"In PD Controller @ line no : 11951 (to Make FaceBoundingBox called ) PDID : ".$pdid); $bounding_box = array(); if(!empty($pdid)){ // $master_details = $this->PD_Model->getPDMasterDetails($pdid);//comment this - if($master_details[0]['pd_status'] == COMPLETED && $master_details[0]['facemark_image_generated'] == 0){ + if($master_details[0]['facemark_image_generated'] == 0){ + log_message('ERROR',"In PD Controller @ line no : 11956 Facemark Image Generated : ".$master_details[0]['facemark_image_generated']); $db_result = $this->PD_Model->selectCustomRecords(array('faceapi_result'),array('pd_id' => $pdid),PDTRIGGER); $string = $db_result[0]['faceapi_result']; // echo gettype($string); @@ -11958,6 +11961,7 @@ public function getCompaniesListsFromGeneralFormRawJSONV2_post() // echo gettype($my_array); if(!empty($my_array) && !empty($my_array["FaceMatches"])){ $arr = $my_array["FaceMatches"]; + log_message('ERROR',"In PD Controller @ line no : 11964 to Make FaceBoundingBox FaceMatches array cnt : ".count($arr)); for($i=0;$iaws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes'); + log_message('ERROR',"In PD Controller @ line no : 11973 to Make FaceBoundingBox FaceMatches singed_uri : ".$singed_uri); // $temp_image_name = "sample.png"; $temp_image_name = "face_api_image.jpeg"; @@ -11982,34 +11987,37 @@ public function getCompaniesListsFromGeneralFormRawJSONV2_post() $bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); + log_message('ERROR',"In PD Controller @ line no : 11990 to Make FaceBoundingBox FaceMatches s3result : ".$s3result['@metadata']['statusCode']); // print_r($s3result);die(); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { + log_message('ERROR',"In PD Controller @ line no : 11996 to Make FaceBoundingBox updating pdtrigger table facemark_image_generated as 1"); //Update $this->db->WHERE('pd_id',$pdid)->UPDATE(PDTRIGGER,array('facemark_image_generated' => 1)); - + log_message('ERROR',"In PD Controller @ line no : 11998 to Make FaceBoundingBox save document table face_api_result_image after unlink"); $record_data = array('fk_pd_id' => $pdid,'pd_document_title'=>'face_api_result_image','pd_document_name'=>$temp_image_name); $this->PD_Model->saveRecords($record_data,PDDOCUMENTS); - unlink($destination_path); } // $data['dataStatus'] = true; // $data['status'] = REST_Controller::HTTP_OK; - // $data['msg'] = 'Given PDID '; + // $data['msg'] = 'Success '; // $data['details'] = $bounding_box; } - // else{ - // $data['dataStatus'] = false; - // $data['status'] = REST_Controller::HTTP_NO_CONTENT; - // $data['msg'] = 'Given PDID is Not in Completed Status'; - // } + else{ + log_message('ERROR',"In PD Controller @ line no : 12009 to Make FaceBoundingBox Faceapi Image Already Generated"); + // $data['dataStatus'] = false; + // $data['status'] = REST_Controller::HTTP_NO_CONTENT; + // $data['msg'] = 'Faceapi Image Already Generated'; + } + } + else{ + log_message('ERROR',"In PD Controller @ line no : 12016 to Make FaceBoundingBox PDID is Not Available"); + // $data['dataStatus'] = false; + // $data['status'] = REST_Controller::HTTP_NO_CONTENT; + // $data['msg'] = 'PDID is Not Available'; } - // else{ - // $data['dataStatus'] = false; - // $data['status'] = REST_Controller::HTTP_NO_CONTENT; - // $data['msg'] = 'PDID is Not Available'; - // } // $this->response($data,REST_Controller::HTTP_OK); } diff --git a/api/application/helpers/faceapi_helper.php b/api/application/helpers/faceapi_helper.php index ac3734a2..fc28974a 100644 --- a/api/application/helpers/faceapi_helper.php +++ b/api/application/helpers/faceapi_helper.php @@ -3,8 +3,11 @@ class faceapi { public static function toMakeFaceBoundingBox($image_name,$BoundingBox,$destination_path){ + log_message('ERROR',"In faceapi helper @ line no : 6 to Make FaceBoundingBox"); $get_image_format = explode(".",$image_name); - // $image_format = $get_image_format[1]; + $image_format = $get_image_format[1]; + log_message('ERROR','In faceapi helper @ line no : 9 to Make FaceBoundingBox image_format :'.$image_format); + // print_r($get_image_format);die(); $img = imagecreatefrompng($destination_path); // if($image_format == 'png'){ // $img = imagecreatefrompng($destination_path); @@ -14,22 +17,19 @@ class faceapi // $img = imagecreatefromjpg($destination_path); // } - $red = imagecolorallocate($img, 255, 0, 0); $black = imagecolorallocate($img, 0, 0, 0); $white = imagecolorallocate($img, 255, 255, 255); - - list($imagewidth, $imageheight) = getimagesize($destination_path); - + log_message('ERROR','In faceapi helper @ line no : 25 to Make FaceBoundingBox image_width'.$imagewidth.'image_height'.$imageheight); for($i=0;$i= 70 ){// above 70 green + log_message('ERROR','In faceapi helper @ line no : 45 Draw Line x1 : '.$x1.' y1 : '.$y1.' Face_width : '.$Face_width.' Face_height : '.$Face_height.' Similarity : '.$Similarity.' img : '.$img.' destination_path : '.$destination_path); + $Similarity_split = explode(".",$Similarity); + $Similarity_value = $Similarity_split[0]; + list($imagewidth, $imageheight) = getimagesize($destination_path); + if($Similarity_value >= 70 ){// above 70 green $color = imagecolorallocate($img, 0, 153, 0); - }else if($Similarity < 70 ){// below 70 red + }else if($Similarity_value < 70 ){// below 70 red $color = imagecolorallocate($img, 255, 0, 0); } - $Similarity = $Similarity." %"; + $white = imagecolorallocate($img, 255, 255, 255); + log_message('ERROR','In faceapi helper @ line no : 45 Draw Line color : '.$color); + $Similarity = $Similarity_value." %"; //TOP LINe $t_x1 = $x1; $t_y1 = $y1; @@ -66,20 +72,24 @@ class faceapi $imgl = self::imagelinethick($img,$t_x2,$t_y2,$b_x2,$b_y2,$color,7);//right line // apppath / doc la roboto.tff $font = APPPATH."docs/roboto.ttf"; - imagettftext($img, 20, 0, ($t_x1), ($t_y1-5), $color,$font, $Similarity); + // imagettftext($img, 20, 0, ($t_x1), ($t_y1-5), $color,$font, $Similarity); // imagepng($img, $destination_path); // imagepng($img, "face4.png"); + // imagefilledrectangle($img, $t_x1-5, $t_y1-18, $t_x1+28, $t_y1, $white); + // imagettftext($img, 10, 10, ($t_x1), ($t_y1-5), $color,$font, $Similarity); + imagefilledrectangle($img, $t_x1-5, $t_y1-30, $t_x1+60, $t_y1, $white); + imagettftext($img, 17, 8, ($t_x1), ($t_y1-5), $color,$font, $Similarity); + $get_image_format = explode(".",$destination_path); $image_format = $get_image_format[1]; if($image_format == 'png'){ - $destination_path = $get_image_format[0].".jpeg"; imagepng($img, $destination_path); }else if($image_format == 'jpeg'){ imagejpeg($img, $destination_path); }else if($image_format == 'jpg'){ - $destination_path = $get_image_format[0].".jpeg"; - imagepng($img, $destination_path); + // $destination_path = $get_image_format[0].".jpeg"; + imagejpg($img, $destination_path); } } diff --git a/api/application/models/Flyhi_Model.php b/api/application/models/Flyhi_Model.php new file mode 100644 index 00000000..90ba047f --- /dev/null +++ b/api/application/models/Flyhi_Model.php @@ -0,0 +1,91 @@ +db->SELECT(' SALES_PD_DATA.sales_pd_sno, SALES_PD_DATA.sales_pd_id, SALES_PD_DATA.applicant_name,concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as officer_name,SALES_PD_DATA.applicant_id,SALES_PD_DATA.lender_id,SALES_PD_DATA.product_id,SALES_PD_DATA.is_pdf,SALES_PD_DATA.is_edited,ENTITY.short_name,PRODUCTS.abbr, + (CASE WHEN SALES_PD_DATA.status = "STARTED" THEN SALES_PD_DATA.createdon WHEN SALES_PD_DATA.status = "COMPLETED" THEN SALES_PD_DATA.completed_date ELSE NULL END) AS createdon, + DATE_FORMAT(SALES_PD_DATA.createdon, "%Y-%m-%d") as pd_createdon, SALES_PD_DATA.status,SALES_PD_DATA.sales_pd_type,SALES_PD_DATA.rand_string'); + $this->db->from(SALES_PD_DATA.' as SALES_PD_DATA'); + $this->db->join(ENTITY.' as ENTITY','ENTITY.entity_id = SALES_PD_DATA.lender_id','INNER'); + $this->db->join(PRODUCTS.' as PRODUCTS', 'PRODUCTS.product_id = SALES_PD_DATA.product_id','INNER'); + $this->db->join(USERPROFILE.' as USERPROFILE', 'USERPROFILE.userid = SALES_PD_DATA.createdby','INNER'); + if(!empty($pd_status)){ + $this->db->where_in('SALES_PD_DATA.status',$pd_status); + } + if(($pd_from_date != "" || $pd_from_date != null) && ($pd_to_date != "" || $pd_to_date != null)) { + // $this->db->where('SALES_PD_DATA.createdon BETWEEN '. "'$pd_from_date'". ' AND '. "'$pd_to_date'" ); + if($pd_status[0] == "STARTED" ){ + $this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d') BETWEEN ". "'$pd_from_date'". ' AND '. "'$pd_to_date'" ); + }else if($pd_status[0] == "COMPLETED" ){ + $this->db->where("DATE_FORMAT(SALES_PD_DATA.completed_date,'%Y-%m-%d') BETWEEN ". "'$pd_from_date'". ' AND '. "'$pd_to_date'" ); + }else{ + $this->db->where("DATE_FORMAT(SALES_PD_DATA.completed_date,'%Y-%m-%d') BETWEEN ". "'$pd_from_date'". ' AND '. "'$pd_to_date'" ); + $this->db->or_where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d') BETWEEN ". "'$pd_from_date'". ' AND '. "'$pd_to_date'" ); + } + } + else if($pd_from_date != "" && $pd_from_date != null) { + // $this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_from_date); + if($pd_status[0] == "STARTED" ){ + $this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_from_date); + }else if($pd_status[0] == "COMPLETED" ){ + $this->db->where("DATE_FORMAT(SALES_PD_DATA.completed_date,'%Y-%m-%d')",$pd_from_date); + }else{ + $this->db->where("DATE_FORMAT(SALES_PD_DATA.completed_date,'%Y-%m-%d')",$pd_from_date); + $this->db->or_where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_from_date); + } + } + else if($pd_to_date != "" && $pd_to_date != null) { + // $this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_to_date); + if($pd_status[0] == "STARTED" ){ + $this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_to_date); + }else if($pd_status[0] == "COMPLETED" ){ + $this->db->where("DATE_FORMAT(SALES_PD_DATA.completed_date,'%Y-%m-%d')",$pd_to_date); + }else{ + $this->db->where("DATE_FORMAT(SALES_PD_DATA.completed_date,'%Y-%m-%d')",$pd_to_date); + $this->db->or_where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_to_date); + } + } + if(!empty($pd_products)){ + $this->db->where_in('SALES_PD_DATA.product_id',$pd_products); + } + if(!empty($pd_lender)) { + $this->db->where_in('SALES_PD_DATA.lender_id',$pd_lender); + } + if(!empty($pd_applicant_name)) { + $this->db->like('SALES_PD_DATA.applicant_name',$pd_applicant_name); + } + if(!empty($pd_officer_name)) { + $this->db->like('SALES_PD_DATA.officer_name',$pd_officer_name); + } + + if(!empty($sales_pd_officer_id)) { + $this->db->WHERE('SALES_PD_DATA.createdby',$sales_pd_officer_id); + } + if(!empty($sales_pd_type) && count($sales_pd_type)) { + $this->db->WHERE_IN('SALES_PD_DATA.sales_pd_type',$sales_pd_type); + } + $this->db->WHERE('SALES_PD_DATA.isactive',1); + $this->db->order_by('SALES_PD_DATA.sales_pd_id','desc'); + $this->db->limit(1000,0); + $result = $this->db->get()->result_array(); + // if(ENVIRONMENT == 'development'){echo 'LAST QUERY '. $this->db->last_query();} + //echo $this->db->last_query();die(); + return $result; + } + public function testSaleSection($id){ + $this->db->SELECT('*')->FROM("t_salespd_section_data")->WHERE('sales_pd_id',$id)->WHERE('isactive',1); + $query = $this->db->get(); + return $query->result(); + // $sql = 'insert into sineedgeprod.t_salespd_section_data(sales_pd_id, section_id, status, section_data, createdby, isactive) select sales_pd_id, section_id, status, section_data, createdby, isactive from sineedgeprod.t_salespd_section_data WHERE sales_pd_id = 1768 and section_id = 1 and isactive = 1;'; + // $modified = $this->db->query($sql); + } + +} \ No newline at end of file