EVOLUTION-NINJA
Edit File: Gss.php
<?php namespace App\Controllers; require_once FCPATH . 'vendor/autoload.php'; use PhpOffice\PhpSpreadsheet\IOFactory; use CodeIgniter\I18n\Time; use App\Controllers\Services; use App\Models\Gss_model; use App\Models\GssNewProjectsModel; use App\Models\BrokerModel; use App\Models\CommissionNotificationModel; use App\Models\ReceptionModel; use DateTime; use DateTimeZone; use CodeIgniter\Email\Email; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; use \Mpdf\Mpdf; class Gss extends BaseController { public function __construct() { $this->db = \Config\Database::connect(); } public function access_id() { $gss_model = new Gss_model(); $id=session()->get('admin_id'); $table='gss_login'; $where=array('user_id'=>$id); $d=$gss_model->get_where_row($table,$where); return $d->user_type_id; } public function access_details() { $gss_model = new Gss_model(); $id=session()->get('admin_id'); $table='gss_login'; $where=array('user_id'=>$id); $d=$gss_model->get_where_row($table,$where); $data['user_type_id']=$d->user_type_id; $table='gss_access_controls'; $where=array('department_id'=>$data['user_type_id']); return $gss_model->get_where_result($table,$where); } public function index() { return view('admin/login'); } public function loans() { $session = session(); $admin_id = $session->get('admin_id'); $loan_user_id = $session->get('loan_user_id'); $db = \Config\Database::connect(); // Fetch all active ongoing projects $data['projects'] = $db->table('gss_new_projects') ->where([ 'delete_status' => 'ACTIVE', 'project_status' => 'ONGOING' ]) ->orderBy('project_name', 'ASC') ->get() ->getResult(); // Get user access details $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); if ($admin_id || $loan_user_id) { return view('admin/loans_list', $data); } else { return redirect()->to(base_url('/')); } } public function get_projects_landownerwise($admin_id, $land_owner_id, $status) { $builder = $this->db->table('gss_new_projects') ->select('project_id, project_name') ->where('delete_status', 'ACTIVE'); if ($land_owner_id != 0) { $builder->where('land_owner_id', $land_owner_id); } if ($status != "ALL") { $builder->where('project_status', $status); } $builder->orderBy('project_name', 'ASC'); $query = $builder->get(); return $query->getResult(); } public function check_project_type_status() { $request = service('request'); $session = session(); $status = $request->getPost('value'); $admin_id = $session->get('admin_id'); $land_owner_id = $session->get('land_owner_id'); $check_status = $this->get_projects_landownerwise($admin_id, $land_owner_id, $status); if ($check_status) { return $this->response->setJSON(['result' => 1, 'message' => $check_status]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } public function get_loans_list() { $project =$this->request->getGet('l_project_id'); $result = $this->getLoansList($project); if($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } public function getLoansList($project) { $db = \Config\Database::connect(); $builder = $db->table('gss_bookings A'); $builder->select('A.*, B.*, A.created_at as booked_on, C.*'); $builder->join('gss_new_projects B', 'B.project_id = A.project_id'); $builder->join('gss_booking_details C', 'C.booking_id = A.booking_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('A.booking_status', 'BOOKED'); if (!empty($project)) { $builder->where('B.project_id', $project); } $builder->orderBy('ABS(A.created_at)', 'DESC'); $result = $builder->get()->getResultArray(); $data=[]; foreach ($result as $val) { $bookingData = [ 'booking_id' => $val['booking_id'], 'customer_name' => $val['customer_name'], 'address' => $val['address'], 'customer_mobile' => $val['mobile1'], 'customer_mobile2' => $val['mobile2'], 'customer_email' => $val['email'], 'project_name' => $val['project_name'], 'site_number' => $val['site_number'], 'dimension' => $val['dimension'], 'booked_on' => $val['booked_on'], 'booking_status' => $val['booking_status'], 'agreement_due_date' => $val['sales_agreement_due_date'], 'source_type' => $val['source_type'], 'agreement_executed_on' => '', 'web_portal' => '', 'logistics' => '', 'reference' => '', 'associate' => '' ]; $aggrQuery = $db->table('gss_plot_payments') ->select('agreement_date') ->where('delete_status', 'ACTIVE') ->where('booking_id', $val["booking_id"]) ->where('agreement_date !=', '0000-00-00') ->get()->getRow(); if ($aggrQuery) { $bookingData['agreement_executed_on'] = $aggrQuery->agreement_date; } if ($val["webportal"] != 0) { $webQuery = $db->table('gss_webportals A') ->select('A.webportal as portal') ->join('gss_bookings B', 'B.webportal = A.portal_id') ->where('B.delete_status', 'ACTIVE') ->where('A.portal_id', $val["webportal"]) ->get()->getRow(); if ($webQuery) { $bookingData['web_portal'] = $webQuery->portal; } } if ($val["logistics"] != 0) { $logisticsQuery = $db->table('gss_brokers A') ->select('A.associate_name as logistic') ->join('gss_bookings B', 'B.logistics = A.broker_id') ->where('B.delete_status', 'ACTIVE') ->where('A.broker_id', $val["logistics"]) ->get()->getRow(); if ($logisticsQuery) { $bookingData['logistics'] = $logisticsQuery->logistic; } } // Fetch reference name if ($val["reference"] != 0) { $referenceQuery = $db->table('gss_brokers A') ->select('A.associate_name as reference') ->join('gss_bookings B', 'B.reference = A.broker_id') ->where('B.delete_status', 'ACTIVE') ->where('A.broker_id', $val["reference"]) ->get()->getRow(); if ($referenceQuery) { $bookingData['reference'] = $referenceQuery->reference; } } // Fetch associate name if ($val["associate"] != 0) { $associateQuery = $db->table('gss_brokers A') ->select('A.associate_name as associate') ->join('gss_bookings B', 'B.associate = A.broker_id') ->where('B.delete_status', 'ACTIVE') ->where('A.broker_id', $val["associate"]) ->get()->getRow(); if ($associateQuery) { $bookingData['associate'] = $associateQuery->associate; } } $data[] = $bookingData; // print_r($data);die(); } return $data; } public function getLoansagreeList($project) { $db = \Config\Database::connect(); $builder = $db->table('gss_bookings A') ->select('A.*, B.*, A.created_at as booked_on, C.*, D.agreement_date') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->join('gss_booking_details C', 'C.booking_id = A.booking_id') ->join('gss_plot_payments D', 'D.booking_id = A.booking_id') ->where('D.agreement_date !=', '0000-00-00') ->where('D.agreement_date !=', '') ->where('D.delete_status', 'ACTIVE') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('C.delete_status', 'ACTIVE'); if ($project != '') { $builder->where('B.project_id', $project); } $builder->groupBy('D.booking_id'); $builder->orderBy("D.agreement_date", "DESC"); $result = $builder->get()->getResult(); $array = []; foreach ($result as $val) { $data = [ 'booking_id' => $val->booking_id, 'customer_name' => $val->customer_name, 'address' => $val->address, 'customer_mobile' => $val->mobile1, 'customer_mobile2' => $val->mobile2, 'customer_email' => $val->email, 'project_name' => $val->project_name, 'site_number' => $val->site_number, 'dimension' => $val->dimension, 'booked_on' => $val->booked_on, 'booking_status' => $val->booking_status, 'agreement_due_date' => $val->sales_agreement_due_date, 'source_type' => $val->source_type, 'agreement_executed_on' => $val->agreement_date, 'web_portal' => '', 'logistics' => '', 'reference' => '', 'associate' => '', ]; // Fetch Web Portal Name if ($val->webportal != 0) { $web_result = $this->db->table('gss_webportals A') ->select('A.webportal') ->join('gss_bookings B', 'B.webportal = A.portal_id') ->where('B.delete_status', 'ACTIVE') ->where('A.portal_id', $val->webportal) ->get() ->getRow(); $data['web_portal'] = $web_result ? $web_result->webportal : ''; } // Fetch Logistics Name if ($val->logistics!= 0) { $logistic_result = $this->db->table('gss_brokers A') ->select('A.associate_name as logistic') ->join('gss_bookings B', 'B.logistics = A.broker_id') ->where('B.delete_status', 'ACTIVE') ->where('A.broker_id', $val->logistics) ->get() ->getRow(); $data['logistics'] = $logistic_result ? $logistic_result->logistic : ''; } // Fetch Reference Name if ($val->reference != 0) { $reference_result = $this->db->table('gss_brokers A') ->select('A.associate_name as reference') ->join('gss_bookings B', 'B.reference = A.broker_id') ->where('B.delete_status', 'ACTIVE') ->where('A.broker_id', $val->reference) ->get() ->getRow(); $data['reference'] = $reference_result ? $reference_result->reference : ''; } // Fetch Associate Name if ($val->associate != 0) { $associate_result = $this->db->table('gss_brokers A') ->select('A.associate_name as associate') ->join('gss_bookings B', 'B.associate = A.broker_id') ->where('B.delete_status', 'ACTIVE') ->where('A.broker_id', $val->associate) ->get() ->getRow(); $data['associate'] = $associate_result ? $associate_result->associate : ''; } $array[] = $data; } return $array; } public function get_loansagree_list() { $project =$this->request->getGet('l_project_id'); $result = $this->getLoansagreeList($project); if($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } public function accounts() { $admin_id = session()->get('admin_id'); if($admin_id) { $result['accounts'] = $this->account_management_list(); $result['user_type_id'] = $this->access_id(); $result['access'] = $this->access_details(); return view('admin/accounts',$result); } else { redirect('/'); } } public function account_management_list() { $builder = $this->db->table('gss_management A'); $builder->select('A.*, B.*, C.*, D.*, E.*, B.mobile1 as customer_contact'); $builder->join('gss_bookings B', 'B.booking_id = A.booking_id'); $builder->join('gss_booking_details C', 'C.detail_id = A.detail_id'); $builder->join('gss_new_projects D', 'D.project_id = B.project_id'); $builder->join('gss_brokers E', 'E.broker_id = B.associate'); // Filtering Active Records $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('D.delete_status', 'ACTIVE'); // Grouping and Ordering $builder->groupBy('A.booking_id'); $builder->orderBy('A.management_id', 'DESC'); $query = $builder->get(); return $query->getResult(); } // Follow Ups ARe Starts Here....................................................... public function follow_ups() { $admin_id = session()->get('admin_id'); $type=session()->get('user_type_id'); // print_r($type);die(); $gss_model=new Gss_model(); if($admin_id) { $land_table = 'gss_new_projects'; $project_id=$this->request->getPost('project_id'); $site_type=$this->request->getPost('site_type'); if($type != 1 && $type != 4) { $where=['handled_by'=>$admin_id]; $data['owners'] = $gss_model->get_where_user($where); $data['details'] =$gss_model->get_user_details($where); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/follow_up_details',$data); } else if($type == 4) { $where=array('handled_by'=>$admin_id); $data['owners'] = $gss_model->get_documents(); $data['details'] =$gss_model->get_user_details($where); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/follow_up_details',$data); } else { $current_date = date('Y-m-d'); $data['owners'] = $gss_model->get_where_alluser($land_table,$current_date); $data['details'] =$gss_model->get_alluser_details($current_date); $project_table = 'gss_new_projects'; $where_project = array('delete_status'=>'ACTIVE','project_status'=>'ONGOING'); $projects_order_by = 'project_name'; $data['projects'] = $gss_model->get_where_result_orderby_asc($project_table,$where_project,$projects_order_by); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/admin_follow_up_details',$data); } } else { redirect('/'); } } public function call_follow_up() { $db = \Config\Database::connect(); $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $detail_id = $this->request->getPost('reminder_id'); $uri = $_SERVER["REQUEST_URI"]; $val = substr($uri, strpos($uri, "=") + 1); $where = $val; $where1 = ['handled_by' => $admin_id]; // Fetch data directly in the controller $data['detailSS'] = $this->db->table('gss_bookings A') ->select('A.customer_name, A.address, B.project_id, B.project_name, B.handled_by, C.site_number, C.tsv, C.tsv_per_sft_rs, C.detail_id') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->join('gss_booking_details C', 'C.booking_id = A.booking_id') ->where('C.detail_id', $where) ->get()->getRow(); $data['detail'] = $this->db->table('gss_new_projects A') ->select('E.id, E.user_id, E.detail_id, E.conversation, E.user_reply, E.reminder, E.close_status, E.comment, E.site_number, E.created_at, A.handled_by, A.project_name, A.project_id, B.user_id, C.detail_id, C.tsv, C.tsv_per_sft_rs, C.updated_at, D.customer_name, D.address') ->join('gss_login B', 'B.user_id = A.handled_by') ->join('gss_booking_details C', 'C.project_id = A.project_id') ->join('gss_bookings D', 'D.booking_id = C.booking_id') ->join('gss_follow_ups E', 'C.detail_id = E.detail_id') ->where('C.detail_id', $where) ->orderBy('E.id', 'DESC') ->get()->getResult(); $data['comment'] = $this->db->table('gss_comment E') ->select('E.id, E.detail_id, E.user_id, E.comment, E.comment_date, E.site_number, F.id AS conversation_id') ->join('gss_follow_ups F', 'F.id = E.conversation_id') ->where('E.detail_id', $where) ->orderBy('E.id', 'ASC') ->get()->getResult(); $data['reply'] = $this->db->table('gss_reply E') ->select('E.id, E.detail_id, E.user_id, E.user_reply, E.reply_date, F.id AS comment_id, F.conversation_id') ->join('gss_comment F', 'F.id = E.comment_id') ->where('E.detail_id', $where) ->orderBy('E.id', 'ASC') ->get()->getResult(); // Access and permissions $data['user_type_id'] = $session->get('user_type_id'); $data['access'] = []; return view('admin/follow_up', $data); } public function add_conversation() { $db = \Config\Database::connect(); $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $detail_id = $this->request->getPost('reminder_id'); $call_convo = $this->request->getPost('call_convo'); // Get conversation details $details = $this->db->table('gss_new_projects A') ->select('A.handled_by, A.project_name, A.project_id, B.user_id, C.detail_id, C.tsv, C.tsv_per_sft_rs, C.site_number, C.project_id AS proj_id, C.booking_id, D.booking_id AS book_id, D.customer_name, D.address') ->join('gss_login B', 'B.user_id = A.handled_by') ->join('gss_booking_details C', 'C.project_id = A.project_id') ->join('gss_bookings D', 'D.booking_id = C.booking_id') ->where('C.detail_id', $detail_id) ->get()->getRow(); if (!$details) { return json_encode(['error' => 'No details found']); } $created_at = date('Y-m-d'); $updated_at = date('d-m-Y'); // Insert conversation $data = [ 'user_id' => $admin_id, 'detail_id' => $details->detail_id, 'project_id' => $details->project_id, 'site_number' => $details->site_number, 'conversation' => $call_convo, 'conversation_status' => 'ONGOING', 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $this->db->table('gss_follow_ups')->insert($data); $insert_id = $this->db->insertID(); // Get last insert ID if ($insert_id) { // Update booking details $this->db->table('gss_booking_details') ->where('detail_id', $details->detail_id) ->update(['updated_at' => $updated_at]); echo json_encode($insert_id); } else { echo json_encode(['error' => 'Insert failed']); } } public function get_follow_project_details() { $db = \Config\Database::connect(); $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } // Get project names $data['project_names'] = $this->db->table('gss_new_projects A') ->select('A.*') ->join('gss_land_owners B', 'B.owner_id = A.land_owner_id') ->where('B.delete_status', 'ACTIVE') ->where('A.delete_status', 'ACTIVE') ->where('B.name !=', 'Gss') ->groupBy('A.project_id') ->get()->getResult(); // Get follow-up details $project_id = $this->request->getPost('id'); $current_date = date('d-m-Y'); $data['details'] = $this->db->table('gss_booking_details A') ->select('A.site_number, A.detail_id, A.project_id, A.booking_id, A.tsv, A.tsv_per_sft_rs, A.updated_at, C.project_id, C.customer_name, C.address, C.booking_id, D.project_id, D.project_name, D.handled_by') ->join('gss_bookings C', 'C.booking_id = A.booking_id') ->join('gss_new_projects D', 'D.project_id = C.project_id') ->where('A.project_id', $project_id) ->orderBy('A.updated_at', 'DESC') ->get()->getResult(); if (!empty($data['details'])) { return $this->response->setJSON(['result' => 1, 'details' => $data['details']]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_admin_follow_project_details() { $db = \Config\Database::connect(); $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } // Get project names $data['project_names'] = $this->db->table('gss_new_projects A') ->select('A.*') ->join('gss_land_owners B', 'B.owner_id = A.land_owner_id') ->where('B.delete_status', 'ACTIVE') ->where('A.delete_status', 'ACTIVE') ->where('B.name !=', 'Gss') ->groupBy('A.project_id') ->get()->getResult(); // Get follow-up details $project_id = $this->request->getPost('id'); $site_number = $this->request->getPost('site_number'); $current_date = date('d-m-Y'); $data['details'] = $this->db->table('gss_booking_details A') ->select('A.site_number, A.detail_id, A.project_id, A.booking_id, A.tsv, A.tsv_per_sft_rs, A.updated_at, C.project_id, C.customer_name, C.address, C.booking_id, D.project_id, D.project_name, D.handled_by') ->join('gss_bookings C', 'C.booking_id = A.booking_id') ->join('gss_new_projects D', 'D.project_id = C.project_id') ->where('A.updated_at', $current_date) ->orderBy('A.updated_at', 'DESC') ->get()->getResult(); if (!empty($data['details'])) { return $this->response->setJSON(['result' => 1, 'details' => $data['details']]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_follow_up_project() { $db = \Config\Database::connect(); $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $project_id = $this->request->getPost('project_id'); $site_number = $this->request->getPost('site_number'); $result = $this->db->table('gss_new_projects A') ->select('A.project_id, A.project_name, A.handled_by, C.site_number, C.detail_id, C.project_id, C.booking_id, C.tsv, C.tsv_per_sft_rs, C.updated_at, D.project_id, D.customer_name, D.address, D.booking_id') ->join('gss_booking_details C', 'C.project_id = A.project_id') ->join('gss_bookings D', 'D.booking_id = C.booking_id') ->where('C.project_id', $project_id) ->where('C.site_number', $site_number) ->get()->getRow(); if ($result) { return $this->response->setJSON(['result' => 1, 'detail' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Site Details Not Available"]); } } public function get_follow_up_project_datewise() { $db = \Config\Database::connect(); $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $from_date = $this->request->getPost('from_date'); $to_date = $this->request->getPost('to_date'); $result = $this->db->table('gss_new_projects A') ->select('A.project_id, A.project_name, A.handled_by, C.site_number, C.detail_id, C.project_id, C.booking_id, C.tsv, C.tsv_per_sft_rs, C.updated_at, D.project_id, D.customer_name, D.address, D.booking_id') ->join('gss_booking_details C', 'C.project_id = A.project_id') ->join('gss_bookings D', 'D.booking_id = C.booking_id') ->where('C.updated_at >=', $from_date) ->where('C.updated_at <=', $to_date) ->orderBy('C.updated_at', 'ASC') ->get() ->getResult(); if ($result) { $dataArray = []; foreach ($result as $row) { $dataArray[] = [ 'detail_id' => $row->detail_id, 'customer_name' => $row->customer_name, 'address' => $row->address, 'project_name' => $row->project_name, 'site_number' => $row->site_number, 'tsv' => $row->tsv, 'tsv_per_sft_rs'=> $row->tsv_per_sft_rs, 'updated_at' => $row->updated_at, ]; } return $this->response->setJSON(['result' => 1, 'detail' => $dataArray]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Site Details Not Available"]); } } public function single_project_sites() { $db = \Config\Database::connect(); $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $project_id = $this->request->getPost('project_id'); if (!$project_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid Project ID']); } $result = $this->db->table('gss_new_sites') ->where('project_id', $project_id) ->orderBy('ABS(site_number)', 'ASC') ->get() ->getResult(); if ($result) { return $this->response->setJSON(['result' => 1, 'sites' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No sites found for this project']); } } //preethi public function land_owner_form() { $admin_id = session()->get('admin_id'); if($admin_id) { $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/land_owner_form',$data); } else { redirect('/'); } } public function land_owner_list() { $admin_id = session()->get('admin_id'); if($admin_id) { $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/land_owners_list',$data); } else { redirect('/'); } } public function add_land_owners() { $gss_model=new Gss_model(); $project = $this->request->getPost('project_name'); $name = $this->request->getPost('name'); $email = $this->request->getPost('email'); $mobile = $this->request->getPost('mobile'); $address = $this->request->getPost('address'); $pan_or_adhar = $this->request->getPost('pan_or_adhar'); $load = $image = \Config\Services::image(); $file_name = ""; if($_FILES) { if(empty($_FILES['id_proof_image']['name'])) { $file_name = ""; } else { $target='public/land_owners_images/'; $target.=time().$_FILES['id_proof_image']['name']; $file_name=time().$_FILES['id_proof_image']['name']; $image=$target; move_uploaded_file($_FILES['id_proof_image']['tmp_name'],$target); $config['source_image']=$target; $config['maintain_ratio']=TRUE; $config['width']=200; $config['height']=150; // $this->image_lib->initialize($config); // $this->image_lib->resize(); $image = \Config\Services::image(); $image->withFile($target) ->resize(200, 150, true) // Resize the image while maintaining the aspect ratio ->save($target); // Save the resized image } } $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $data = array( 'project_name' => $project, 'name' => $name, 'email' => $email, 'mobile' => $mobile, 'address' => $address, 'pan_or_adhar_number' => $pan_or_adhar, 'id_proof_image' => $file_name, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ); $land_table = 'gss_land_owners'; $image_table = 'gss_land_images'; $where = array('delete_status'=>'ACTIVE'); $numbers = $gss_model->get_where_result($land_table,$where); $array = array(); $check_owner = $gss_model->check_land_owners($project,$name,$mobile); if($check_owner) { return $this->response->setJSON(['result'=>2,'message'=>"Land owner already exists"]); } else { $result = $gss_model->insert1($land_table,$data); if($result) { return $this->response->setJSON(['result'=>1,'message'=>"Land owner details added successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); } } } //Land owners list public function land_owners_list() { $gss_model=new Gss_model(); $table = 'gss_land_owners'; $where = array('delete_status'=>'ACTIVE'); $order_by = "name"; $result = $gss_model->get_where_result_alphabetical($table,$where,$order_by); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function delete_land_owner() { try { $gss_model = new Gss_model(); $owner_id = $this->request->getPost('owner_id'); if (!$owner_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid owner ID']); } $table = 'gss_land_owners'; $where = ['owner_id' => $owner_id]; $data = ['delete_status' => 'INACTIVE']; $updated = $gss_model->update1($table, $where, $data); // ✅ Call model function if ($updated) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No changes made']); } } catch (\Exception $e) { return $this->response->setJSON(['result' => 0, 'message' => 'Error: ' . $e->getMessage()]); } } //Edit land owner public function edit_land_owner() { $gss_model=new Gss_model(); $table = 'gss_land_owners'; $owner_id = $this->request->getpost('owner_id'); $where = array('owner_id'=>$owner_id,'delete_status'=>'ACTIVE'); $result = $gss_model->get_where_row($table,$where); if($result) { return $this->response->setJSON(['land_owners_details'=>$result,'result'=>1]); } else { return $this->response->setJSON(['result'=>0]); } } //Update land owners public function update_land_owner() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $table = 'gss_land_owners'; $owner_id = $this->request->getpost('owner_id'); $name = $this->request->getpost('name'); $project_name = $this->request->getpost('project_name'); $email = $this->request->getpost('email'); $mobile = $this->request->getpost('mobile'); $address = $this->request->getpost('address'); $pan_or_adhar = $this->request->getpost('pan_or_adhar'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); // print_r($id_proof);die(); $where_file = ['owner_id' => $owner_id]; $file_data = $gss_model->get_where_row($table,$where_file); $id_proof = isset($file_data->id_proof_image) ? $file_data->id_proof_image : null; if(empty($_FILES['id_proof_image']['name'])) { $data = array( 'name' => $name, 'project_name' => $project_name, 'email' => $email, 'mobile' => $mobile, 'address' => $address, 'pan_or_adhar_number' => $pan_or_adhar, 'id_proof_image' => $id_proof, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ); } else { $load = $image = \Config\Services::image(); $target='public/land_owners_images/'; $target.=time().$_FILES['id_proof_image']['name']; $file_name=time().$_FILES['id_proof_image']['name']; $image=$target; move_uploaded_file($_FILES['id_proof_image']['tmp_name'],$target); $config['source_image']=$target; $config['maintain_ratio']=TRUE; $config['width']=200; $config['height']=450; $image = \Config\Services::image(); $image->withFile($target) ->resize(200, 150, true) // Resize the image while maintaining the aspect ratio ->save($target); $data = array( 'name' => $name, 'project_name' => $project_name, 'email' => $email, 'mobile' => $mobile, 'address' => $address, 'pan_or_adhar_number' => $pan_or_adhar, 'id_proof_image' => $file_name, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ); } // $where_mobile = $file_data->mobile; $where_mobile = isset($file_data->mobile) ? $file_data->mobile : null; $where = array('delete_status'=>'ACTIVE','mobile !='=>$where_mobile); $numbers = $gss_model->get_where_result($table,$where); $array = array(); foreach($numbers as $value) { array_push($array, $value->mobile); } if(in_array($mobile,$array)) { return $this->response->setJSON(['result' => 2, 'message' => 'Contact number already exists']); } else { $where_id = ['owner_id'=>$owner_id]; $result = $gss_model->update1($table,$where_id,$data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to update. Try again']); } } } public function enquiry_form() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $table = 'gss_webportals'; $broker_table = 'gss_brokers'; $databasetable ='gss_database'; $where = array('delete_status'=>'ACTIVE'); $where_reference = array('delete_status'=>'ACTIVE','type'=>'Executives'); $order_by1 = 'associate_name'; $order_by2 = 'webportal'; $order_by3 = 'database_name'; $data['reference'] = $gss_model->get_where_result_alphabetical($broker_table,$where_reference,$order_by1); $data['webportals'] = $gss_model->get_where_result_alphabetical($table,$where,$order_by2); $data['database'] = $gss_model->get_where_result_alphabetical($databasetable,$where,$order_by3); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/enquiry_form',$data); } else { redirect('/'); } } //Enquiry form public function enquiry_list() { $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $table = 'gss_webportals'; $broker_table = 'gss_brokers'; $databasetable ='gss_database'; $where = array('delete_status'=>'ACTIVE'); $where_reference = array('delete_status'=>'ACTIVE','type'=>'Executives'); $order_by1 = 'associate_name'; $order_by2 = 'webportal'; $order_by3 = 'database_name'; $data['reference'] = $gss_model->get_where_result_alphabetical($broker_table,$where_reference,$order_by1); $data['webportals'] = $gss_model->get_where_result_alphabetical($table,$where,$order_by2); $data['database'] = $gss_model->get_where_result_alphabetical($databasetable,$where,$order_by3); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/enquiry_list',$data); } else { redirect('/'); } } //Add enquiries public function add_enquiries() { $gss_model=new Gss_model(); $name = ucfirst($this->request->getpost('name')); $email = $this->request->getpost('email'); $mobile = $this->request->getpost('mobile'); $mobile2 = $this->request->getpost('mobile2'); $address = $this->request->getpost('address'); $web_portal = $this->request->getpost('web_portal'); $reference = $this->request->getpost('reference'); $database = $this->request->getpost('database'); $status = $this->request->getpost('status'); $day = $this->request->getpost('day'); //$date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = date("Y-m-d", strtotime($day)); $table = 'gss_enquiries'; $data = array( 'customer_name' => ucfirst($name), 'email' => $email, 'mobile' => $mobile, 'mobile2' => $mobile2, 'address' => $address, 'web_portal_address' => $web_portal, 'reference' => $reference, 'database_name' => $database, 'status' => $status, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ); $contacts = $gss_model->check_enquiries($name,$mobile); if($contacts) { return $this->response->setJSON(['result'=>2,'message'=>"Customer details already exists"]); } else { $result = $gss_model->insert1($table,$data); if($result) { return $this->response->setJSON(['result'=>1,'message'=>"Enquiry added successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); } } } public function enquiries() { $gss_model=new Gss_model(); $customer_name = $_GET['customer_name']; $table = 'gss_enquiries'; $where = array('delete_status'=>'ACTIVE'); $order_by = 'enquiry_id'; $result = $gss_model->get_where_result_orderby_desc1($table,$where,$order_by,$customer_name); // print_r($customer_name); // die(); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } // public function enquiries_list() // { // $gss_model=new Gss_model(); // $from_date = $_GET['from_date']; // if($from_date != "") // { // $date = new DateTime($from_date); // $from_date = $date->format('Y-m-d'); // } // $to_date =$_GET['to_date']; // if($to_date != "") // { // $date = new DateTime($to_date); // $to_date = $date->format('Y-m-d'); // } // $customer_name = $_GET['customer_name']; // $table = 'gss_enquiries'; // $result = $gss_model->get_where_result1($table,$from_date,$to_date,$customer_name); // echo json_encode($result); // } public function enquiries_list() { $gss_model = new Gss_model(); // ✅ Validate and Format 'from_date' $from_date = $this->request->getGet('from_date'); if (!empty($from_date) && strtotime($from_date)) { $from_date = (new \DateTime($from_date))->format('Y-m-d'); // ✅ Use `\DateTime` } else { $from_date = null; // Default value if invalid } // ✅ Validate and Format 'to_date' $to_date = $this->request->getGet('to_date'); if (!empty($to_date) && strtotime($to_date)) { $to_date = (new \DateTime($to_date))->format('Y-m-d'); // ✅ Use `\DateTime` } else { $to_date = null; // Default value if invalid } // ✅ Get Customer Name (No Validation Needed) $customer_name = $this->request->getGet('customer_name'); $table = 'gss_enquiries'; $result = $gss_model->get_where_result1($table, $from_date, $to_date, $customer_name); return $this->response->setJSON($result); } //Delete enquiries public function delete_enquiries() { $gss_model = new Gss_model(); $db = \Config\Database::connect(); $table = 'gss_enquiries'; // ✅ Validate input $enquiry_id = $this->request->getPost('enquiry_id'); if (empty($enquiry_id)) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid Enquiry ID']); } $where = ['enquiry_id' => $enquiry_id]; $data = ['delete_status' => 'INACTIVE']; // ✅ Ensure `update1()` works correctly $result = $gss_model->update1($table, $where, $data); if ($result > 0) { // ✅ Use `$result` instead of `$db->affectedRows()` return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to delete or already inactive']); } } //Edit enquiry public function edit_enquiries() { $gss_model=new Gss_model(); $table = 'gss_enquiries'; $enquiry_id = $this->request->getpost('enquiry_id'); $where = array('enquiry_id'=>$enquiry_id,'delete_status'=>'ACTIVE'); $result = $gss_model->get_where_row($table,$where); if($result) { return $this->response->setJSON(['enquiry_details'=>$result,'result'=>1]); } else { return $this->response->setJSON(['result'=>0]); } } //Update enquiry public function update_enquiry() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $table = 'gss_enquiries'; $enquiry_id = $this->request->getpost('enquiry_id'); $name = $this->request->getpost('name'); $email = $this->request->getpost('email'); $mobile = $this->request->getpost('mobile'); $mobile2 = $this->request->getpost('mobile2'); $address = $this->request->getpost('address'); $web_portal = $this->request->getpost('web_portal'); $database = $this->request->getpost('database_name'); $reference = $this->request->getpost('reference'); $status = $this->request->getpost('status'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); $data = array( 'customer_name' => $name, 'email' => $email, 'mobile' => $mobile, 'mobile2' => $mobile2, 'address' => $address, 'web_portal_address' => $web_portal, 'reference' => $reference, 'database_name' => $database, 'status' => $status, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ); $where_id = ['enquiry_id' => $enquiry_id]; $result = $gss_model->update1($table,$where_id,$data); if($result > 0) { return $this->response->setJSON(['result'=>1,'message'=>"Updated successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Failed to update. Try again"]); } } public function associate_broker_form() { $admin_id = session()->get('admin_id'); if($admin_id) { $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/associative_executive_logistic_form',$data); } else { redirect('/'); } } //Associate / Executive / Logistic form list public function associate_broker_list() { $admin_id = session()->get('admin_id'); if($admin_id) { $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/associative_executive_logistic_list',$data); } else { redirect('/'); } } //Booking form public function bookings() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $web_table = 'gss_webportals'; $broker_table = 'gss_brokers'; $project_table = 'gss_new_projects'; $where_portal = array('delete_status'=>'ACTIVE'); $where_associate = array('delete_status'=>'ACTIVE','type'=>'Associate'); $where_subassociate = array('delete_status'=>'ACTIVE','type'=>'Sub Associate'); $where_logistics = array('delete_status'=>'ACTIVE','type'=>'Logistic'); $where_reference = array('delete_status'=>'ACTIVE','type'=>'Executives'); $where_project = array('delete_status'=>'ACTIVE','project_status'=>'ONGOING'); //$where_project = array('delete_status'=>'ACTIVE'); $order_by = 'associate_name'; $order_by_portal = 'webportal'; $order_by_project = 'project_name'; $data['webportals'] = $gss_model->get_where_result_alphabetical($web_table,$where_portal,$order_by_portal); $data['associates'] = $gss_model->get_where_result_orderby_asc($broker_table,$where_associate,$order_by); $data['subassociates'] = $gss_model->get_where_result_orderby_asc($broker_table,$where_subassociate,$order_by); $data['logistics'] = $gss_model->get_where_result_orderby_asc($broker_table,$where_logistics,$order_by); $data['reference'] = $gss_model->get_where_result_orderby_asc($broker_table,$where_reference,$order_by); $data['projects'] = $gss_model->get_where_result_orderby_asc($project_table,$where_project,$order_by_project); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/booking_form',$data); } else { redirect('/'); } } //Booked sites public function booked_sites() { $admin_id = session()->get('admin_id'); if($admin_id) { $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/booked_sites',$data); } else { redirect('/'); } } public function add_brokers() { $gss_model=new Gss_model(); $name_or_id = $this->request->getPost('name_or_id'); $type = $this->request->getPost('type'); if($type == 'Executives') { $basic_target = $this->request->getPost('basic_target'); $incentive_type = $this->request->getPost('incentive_type'); if($incentive_type == "incentive_in_percentage") { $incentive_percent = $this->request->getPost('incentive_in_percentage'); $incentive_rupees = ''; } else { $incentive_percent = ''; $incentive_rupees = $this->request->getPost('incentive_in_rs'); } $incentive_target_rs = ""; } else if($type == 'Logistic') { $basic_target = ""; $incentive_type = ""; $incentive_percent = ""; $incentive_rupees = ""; $incentive_target_rs = $this->request->getPost('incentive_target'); } else { $basic_target = ""; $incentive_type = ""; $incentive_percent = ""; $incentive_rupees = ""; $incentive_target_rs= ""; } $associate_name = $this->request->getPost('associate_name'); $email = $this->request->getPost('email'); $mobile = $this->request->getPost('mobile'); $mobile2 = $this->request->getPost('mobile2'); $address = $this->request->getPost('address'); $pan_number = $this->request->getPost('pan_number'); $adhar_number = $this->request->getPost('adhar_number'); $reference_details = $this->request->getPost('reference_details'); // $this->load->library('image_lib'); $image = \Config\Services::image(); // ✅ Correct way in CI4 if($_FILES) { if(empty($_FILES['scan_copy']['name'])) { $file_name = ""; } else { $uploadPath = WRITEPATH . '../public/broker_uploads/'; // Real path for move() $file = $this->request->getFile('scan_copy'); if ($file && $file->isValid() && !$file->hasMoved()) { $newName = time() . '_' . preg_replace('/\s+/', '_', $file->getClientName()); // Ensure upload directory exists if (!is_dir($uploadPath)) { mkdir($uploadPath, 0755, true); } // Move the file $file->move($uploadPath, $newName); // Absolute full path for resizing $fullPath = $uploadPath . $newName; // Resize the image $image = \Config\Services::image(); $image->withFile($fullPath) ->resize(200, 150, true) ->save($fullPath); } } if(!empty($file_name)) { $file_names = preg_replace('/\s+/', '_', $file_name); } else { $file_names = ""; } $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $data = array( 'type' => $type, 'name_or_id' => $name_or_id, 'associate_name' => $associate_name, 'email' => $email, 'mobile' => $mobile, 'mobile2' => $mobile2, 'address' => $address, 'pan_number' => $pan_number, 'adhar_number' => $adhar_number, 'reference_details' => $reference_details, 'scan_copy' => $file_names, 'basic_target' => $basic_target, 'incentive_type' => $incentive_type, 'incentive_percent' => $incentive_percent, 'incentive_rupees' => $incentive_rupees, 'incentive_target_rs' => $incentive_target_rs, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ); $table = 'gss_brokers'; $result = $gss_model->insert1($table,$data); if($result) { return $this->response->setJSON(['result'=>1,'message'=>"Broker details added successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); } }} public function brokers_list() { $gss_model=new Gss_model(); $type = $_GET['type']; $table = 'gss_brokers'; $order_by = "associate_name"; $where = array('type'=>$type,'delete_status' => 'ACTIVE',); $result = $gss_model->get_where_result_alphabetical_broker($table,$where,$order_by); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } //Delete broker public function delete_broker() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $table = 'gss_brokers'; $broker_id = $this->request->getPost('broker_id'); $where = array('broker_id'=>$broker_id); $data = array('delete_status'=>'INACTIVE'); $result = $gss_model->update1($table, $where, $data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result'=>1,'message'=>'Deleted successfully']); } else { return $this->response->setJSON(['result'=>0]); } } //Edit broker public function edit_broker() { $gss_model=new Gss_model(); $type = $_GET['type']; $table = 'gss_brokers'; // $broker_id = $input->post('broker_id'); $broker_id = $this->request->getPost('broker_id'); $where = array('type'=>$type,'broker_id'=>$broker_id,'delete_status'=>'ACTIVE'); $result = $gss_model->get_where_row($table,$where); if($result) { return $this->response->setJSON(['broker_details'=>$result,'result'=>1]); } else { return $this->response->setJSON(['result'=>0]); } } public function update_broker() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $type = $_GET['type']; if($type == 'Executives') { $basic_target = $this->request->getpost('basic_target'); $incentive_type = $this->request->getpost('incentive_type'); if($incentive_type == "incentive_in_percentage") { $incentive_percent = $this->request->getpost('incentive_in_percentage'); $incentive_rupees = ''; } else { $incentive_percent = ''; $incentive_rupees = $this->request->getpost('incentive_in_rs'); } $incentive_target_rs = ""; } else if($type == 'Logistic') { $basic_target = ""; $incentive_type = ""; $incentive_percent = ""; $incentive_rupees = ""; $incentive_target_rs = $this->request->getpost('incentive_target'); } else { $basic_target = ""; $incentive_type = ""; $incentive_percent = ""; $incentive_rupees = ""; $incentive_target_rs= ""; } $table = 'gss_brokers'; $broker_id = $this->request->getpost('broker_id'); //$type = $this->request->getPost('type'); $name_or_id = $this->request->getpost('name_or_id'); $associate_name = $this->request->getpost('associate_name'); $address = $this->request->getpost('address'); $email = $this->request->getpost('email'); $mobile = $this->request->getpost('mobile'); $mobile2 = $this->request->getpost('mobile2'); $reference_details = $this->request->getpost('reference_details'); $pan_number = $this->request->getpost('pan_number'); $adhar_number = $this->request->getpost('adhar_number'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); $where_file = array('type'=>$type,'broker_id'=>$broker_id); $file_data = $gss_model->get_where_row($table,$where_file); $scan_copy = $file_data->scan_copy; if(empty($_FILES['scan_copy']['name'])) { $data = array( 'type' => $type, 'name_or_id' => $name_or_id, 'associate_name' => $associate_name, 'email' => $email, 'mobile' => $mobile, 'mobile2' => $mobile2, 'address' => $address, 'pan_number' => $pan_number, 'adhar_number' => $adhar_number, 'reference_details' => $reference_details, 'scan_copy' => $scan_copy, 'basic_target' => $basic_target, 'incentive_type' => $incentive_type, 'incentive_percent' => $incentive_percent, 'incentive_rupees' => $incentive_rupees, 'incentive_target_rs' => $incentive_target_rs, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ); } else { $image = \Config\Services::image(); $target='public/broker_uploads/'; $target.=time().$_FILES['scan_copy']['name']; $file_name=time().$_FILES['scan_copy']['name']; $image=$target; move_uploaded_file($_FILES['scan_copy']['tmp_name'],$target); $config['source_image']=$target; $config['maintain_ratio']=TRUE; // $config['width']=200; // $config['height']=450; $image = \Config\Services::image(); $image->withFile($target) ->resize(200, 150, true) // Resize the image while maintaining the aspect ratio ->save($target); $data = array( 'type' => $type, 'name_or_id' => $name_or_id, 'associate_name' => $associate_name, 'email' => $email, 'mobile' => $mobile, 'mobile2' => $mobile2, 'address' => $address, 'pan_number' => $pan_number, 'adhar_number' => $adhar_number, 'reference_details' => $reference_details, 'scan_copy' => $file_name, 'basic_target' => $basic_target, 'incentive_type' => $incentive_type, 'incentive_percent' => $incentive_percent, 'incentive_rupees' => $incentive_rupees, 'incentive_target_rs' => $incentive_target_rs, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ); } $where_id = array('broker_id'=>$broker_id,'type'=>$type); $result = $gss_model->update1($table,$where_id,$data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result'=>1,'message'=>"Updated successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Failed to update. Try again"]); } } // New projects form public function project_form() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $land_table = 'gss_land_owners'; $where = array('delete_status'=>'ACTIVE'); $order_by='name'; $data['owners'] = $gss_model->get_where_result_orderby_asc($land_table,$where,$order_by); //$data['owners'] = $this->gss_model->get_where_result($land_table,$where); $land_table1 = 'gss_login'; $where1 = array('delete_status'=>'ACTIVE','user_type_id'=>'5'); $order_by1='username'; $data['users'] = $gss_model->get_where_result_orderby_asc($land_table1,$where1,$order_by1); //$data['users'] = $this->gss_model->get_where_result($land_table1,$where1); //addd $owner_table ="gss_project_ownership"; $where = array('delete_status'=>'ACTIVE'); $data['project_owners'] = $gss_model->get_where_result($owner_table,$where); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); $table2 = "gss_project_master"; $where2 = array('delete_status'=>'ACTIVE'); $data['projects'] = $gss_model->get_where_result($table2,$where2); return view('admin/new_project_form',$data); } else { redirect('/'); } } // projects list form public function project_list() { $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $land_table = 'gss_land_owners'; $where = array('delete_status'=>'ACTIVE'); $data['owners'] = $gss_model->get_where_result($land_table,$where); $owner_table = 'gss_project_ownership'; $where = array('delete_status'=>'ACTIVE'); $data['project_owner'] = $gss_model->get_where_result($owner_table,$where); $land_table1 = 'gss_login'; $where1 = array('delete_status'=>'ACTIVE','user_type_id'=>'5'); $data['users'] = $gss_model->get_where_result($land_table1,$where1); $project_table = "gss_new_projects"; $where2 = array('delete_status'=>'ACTIVE'); $data['projects'] = $gss_model->get_where_result($project_table,$where2); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); $table2 = "gss_project_master"; $where2 = array('delete_status'=>'ACTIVE'); $data['project_master'] = $gss_model->get_where_result($table2,$where2); return view('admin/projects_list',$data); } else { redirect('/'); } } public function add_project() { $gss_model=new Gss_model(); $project = $this->request->getPost('project_name'); $site_type = $this->request->getPost('site_type'); $land_owner = $this->request->getPost('land_owner'); $marketing = $this->request->getPost('marketing'); $handle = $this->request->getPost('handled_by'); $nick_name = $this->request->getPost('nick_name'); $land_owner_address = $this->request->getPost('land_owner_address'); $project_ownership =$this->request->getPost('project_ownership'); $confirming_party_name =$this->request->getPost('confirming_party_name'); $per_sq_ft = $this->request->getPost('per_sq_ft'); $no_of_years = $this->request->getPost('no_of_years'); if(!empty($project_ownership)) { $p_name=$project_ownership; } else { $p_name=$confirming_party_name; } $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d'); $project_table = 'gss_new_projects'; $image_table = 'gss_nine_and_eleven_images'; $nine_and_eleven_image = ""; $release_order_image = ""; $conversion_order_image = ""; //$this->image_lib->library('image_lib'); $image = \Config\Services::image(); if(empty($_FILES['approved_plan_image']['name'])) { $approved_plan_image = ""; } else if ($_FILES) { if (!empty($_FILES['approved_plan_image']['name'])) { $target = 'public/project_uploads/'; $target .= time() . $_FILES['approved_plan_image']['name']; // Generate a unique file name with timestamp $approved_plan_image = time() . $_FILES['approved_plan_image']['name']; $target1 = preg_replace('/\s+/', '_', $target); // Replace spaces with underscores in the target file name $image = $target1; // Assign the target file path to $image move_uploaded_file($_FILES['approved_plan_image']['tmp_name'], $target1); // Initialize the image service and configure the resize options $imageService = \Config\Services::image(); $imageService->withFile($target1) ->resize(200, 150, true) // Resize the image while maintaining the aspect ratio ->save($target1); // Save the resized image back to the same target file } } if(!empty($approved_plan_image)) { $approved_plan_images = preg_replace('/\s+/', '_', $approved_plan_image); } else { $approved_plan_images = ""; } if($_FILES['conversion_order_image']['size'][0] != 0) { for($i = 0; $i < count($_FILES['conversion_order_image']['name']); $i++) { $target1 = 'public/conversion_orders/'; $stamp = getdate(); $target1 .= $stamp[0] . basename($_FILES['conversion_order_image']['name'][$i]); $target2 = $stamp[0] . basename($_FILES['conversion_order_image']['name'][$i]); $target3 = preg_replace('/\s+/', '_', $target1); $url[] = $target2; move_uploaded_file($_FILES['conversion_order_image']['tmp_name'][$i], $target3); // Initialize the image service $imageService = \Config\Services::image(); // Resize and save the image $imageService->withFile($target3) // Provide the correct file path to be resized ->resize(200, 150, true) // Resize the image while maintaining the aspect ratio ->save($target3); // Save the resized image } } if(empty($_FILES['release_order_image']['name'])) { $release_order_image = ""; } else // { // $target='public/release_orders/'; // $target.=time().$_FILES['release_order_image']['name']; // $release_order_image=time().$_FILES['release_order_image']['name']; // $image=$target; // $target1 = preg_replace('/\s+/', '_', $target); // move_uploaded_file($_FILES['release_order_image']['tmp_name'],$target1); // $config['source_image']=$target1; // $config['maintain_ratio']=TRUE; // $config['width']=900; // $config['height']=900; // $image = \Config\Services::image(); // $image->withFile($target) // ->resize(200, 150, true) // Resize the image while maintaining the aspect ratio // ->save($target); // } if($_FILES['release_order_image']['size'] != 0) { // Set the target directory and file name $target = 'public/release_orders/'; $target .= time() . $_FILES['release_order_image']['name']; $release_order_image = time() . $_FILES['release_order_image']['name']; // Replace spaces with underscores $target1 = preg_replace('/\s+/', '_', $target); // Move the uploaded file to the target directory move_uploaded_file($_FILES['release_order_image']['tmp_name'], $target1); // Initialize the image service $imageService = \Config\Services::image(); // Resize the image and save it $imageService->withFile($target1) // Use the file path to be resized ->resize(200, 150, true) // Resize while maintaining the aspect ratio ->save($target1); // Save the resized image } if(!empty($release_order_image)) { $release_order_images = preg_replace('/\s+/', '_', $release_order_image); } else { $release_order_images = ""; } if(!empty($conversion_order_image)) { $conversion_order_images = preg_replace('/\s+/', '_', $conversion_order_image); } else { $conversion_order_images = ""; } $where = array('delete_status'=>'ACTIVE'); $projects = $gss_model->get_where_result($project_table,$where); $array = array(); $check_project = $gss_model->check_project($project); if($check_project) { return $this->response->setJSON(['result'=>2,'message'=>"Project already exists"]); } else { $data = array( 'project_name' => $project, 'site_type' => $site_type, 'land_owner_id' => $land_owner, 'land_owner_address'=> $land_owner_address, 'marketing' => $marketing, 'project_ownership'=>$p_name, 'project_status' => 'ONGOING', 'conversion_image' => $conversion_order_images, 'approval_image' => $approved_plan_images, 'release_image' => $release_order_images, 'handled_by' =>$handle, 'nick_name' =>$nick_name, 'no_of_years' =>$no_of_years, 'maintenance_per_sqft' =>$per_sq_ft, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ); $result = $gss_model->insert1($project_table,$data); if($result) { if(isset($url)) { foreach($url as $key=>$get_url) { $image_table = 'gss_project_conversion_orders'; $gallery_array = array( 'project_id' => $result, 'conversion_order' => $get_url, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ); $gallery = $gss_model->insert1($image_table,$gallery_array); } } // if(isset($_FILES['excel_file']['name'])) // { // date_default_timezone_set('Asia/Kolkata'); // include 'PHPExcel/IOFactory.php'; // $file_name = $_FILES['excel_file']['name']; // $ext = pathinfo($file_name, PATHINFO_EXTENSION); // if($ext == "xlsx" || $ext == "xls") // { // $file_name = $_FILES['excel_file']['tmp_name']; // $inputFileName = $file_name; // try { // $inputFileType = PHPExcel_IOFactory::identify($inputFileName); // $objReader = PHPExcel_IOFactory::createReader($inputFileType); // $objPHPExcel = $objReader->load($inputFileName); // } // catch (Exception $e) // { // die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) // . '": ' . $e->getMessage()); // } // $sheet = $objPHPExcel->getSheet(0); // $highestRow = $sheet->getHighestRow(); // $highestColumn = $sheet->getHighestColumn(); // $allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); // $arrayCount = count($allDataInSheet); // Here get total count of row in that Excel sheet // $table = 'gss_new_sites'; if(isset($_FILES['excel_file']['name'])) { date_default_timezone_set('Asia/Kolkata'); $file_name = $_FILES['excel_file']['name']; $ext = pathinfo($file_name, PATHINFO_EXTENSION); if($ext == "xlsx" || $ext == "xls") { $file_name = $_FILES['excel_file']['tmp_name']; $inputFileName = $file_name; try { // Load the Excel file $spreadsheet = IOFactory::load($inputFileName); } catch (Exception $e) { die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); } $sheet = $spreadsheet->getActiveSheet(); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); $allDataInSheet = $sheet->toArray(null, true, true, true); $arrayCount = count($allDataInSheet); // Total count of rows $table = 'gss_new_sites'; if(count($allDataInSheet)>0){ for($i = 2;$i <= $arrayCount;$i++){ $site_number = trim($allDataInSheet[$i]["A"]); $north_in_mtrs = trim($allDataInSheet[$i]["B"]); $north_in_mtrs = sprintf ("%.2f", $north_in_mtrs); $south_in_mtrs = trim($allDataInSheet[$i]["C"]); $south_in_mtrs = sprintf ("%.2f", $south_in_mtrs); $east_in_mtrs = trim($allDataInSheet[$i]["D"]); $east_in_mtrs = sprintf ("%.2f", $east_in_mtrs); $west_in_mtrs = trim($allDataInSheet[$i]["E"]); $west_in_mtrs = sprintf ("%.2f", $west_in_mtrs); $total_in_sqmtrs = trim($allDataInSheet[$i]["F"]); $total_in_sqmtrs = sprintf ("%.2f", $total_in_sqmtrs); $total_in_sqft = trim($allDataInSheet[$i]["G"]); $total_in_sqft = sprintf ("%.2f", $total_in_sqft); $east_facing = trim($allDataInSheet[$i]["H"]); $west_facing = trim($allDataInSheet[$i]["I"]); $north_facing = trim($allDataInSheet[$i]["J"]); $south_facing = trim($allDataInSheet[$i]["K"]); $status = trim($allDataInSheet[$i]["L"]); $data =array( 'project_id' => $result, 'site_number' => $site_number, 'north_in_mtrs' => $north_in_mtrs, 'south_in_mtrs' => $south_in_mtrs, 'east_in_mtrs' => $east_in_mtrs, 'west_in_mtrs' => $west_in_mtrs, 'total_in_sqmtrs' => $total_in_sqmtrs, 'total_in_sqft' => $total_in_sqft, 'east_facing' => $east_facing, 'west_facing' => $west_facing, 'north_facing' => $north_facing, 'south_facing' => $south_facing, 'status' => $status, 'delete_status' => 'ACTIVE', 'created_at ' => $created_at ); $gss_model->insert1($table,$data); } } } return $this->response->setJSON(['result' => 1, 'message' => 'Project Added successfully']); } else { return $this->response->setJSON(['result' => 3,'message'=>"Please upload file with xlsx extension only"]); } } else { return $this->response->setJSON(['result' => 0,'message'=>"Something went wrong.. try again"]); } } } //Projects list public function projects_list() { $table = 'gss_projects'; $result = $this->gss_model->projects_list(); if($result) { echo json_encode(array('projects_list'=>$result,'result'=>1)); } else { echo json_encode(array('result'=>0)); } } //Delete new project public function delete_new_project() { $gss_model=new Gss_model(); $project_table = 'gss_new_projects'; $sites_table = 'gss_new_sites'; $image_table = 'gss_nine_and_eleven_images'; $project_id = $this->request->getpost('project_id'); $where = array('project_id'=>$project_id); $data = array('delete_status'=>'INACTIVE'); // $result2 = $gss_model->update1($where,$sites_table,$data); // $result4 = $gss_model->update1($where,$image_table,$data); // $result3 = $gss_model->update1($where,$project_table,$data); $result2 = $gss_model->update1($sites_table, $where, $data); // ✅ Correct Order $result4 = $gss_model->update1($image_table, $where, $data); // ✅ Correct Order $result3 = $gss_model->update1($project_table, $where, $data); // ✅ Correct Order //if ($db->affectedRows() > 0) $db = \Config\Database::connect(); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result'=>1,'message'=>'Deleted successfully']); } else { return $this->response->setJSON(['result'=>0]); } } public function project_details() { $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $project_table = 'gss_new_projects'; $sites_table = 'gss_new_sites'; $image_table = 'gss_nine_and_eleven_images'; $conversin_orders = 'gss_project_conversion_orders'; //$project_id = $this->uri->segment(2); $project_id = $this->request->getUri()->getSegment(2); // ✅ CodeIgniter 4 Correct Method $where = array('delete_status'=>'ACTIVE','project_id'=>$project_id); $data['project_id'] = $project_id; $table = 'gss_new_projects'; $where = array('project_id'=>$project_id); $get_land_owner_id = $gss_model->get_where_row($table, $where); $land_owner_id = $get_land_owner_id->land_owner_id; $tables = 'gss_land_owners'; $wheres = array('owner_id'=>$land_owner_id); $data['land_owner'] = $gss_model->get_where_row($tables, $wheres); $condition=array('delete_status'=>'ACTIVE'); $data['project'] = $gss_model->get_where_result($project_table,$condition); $data['mappings'] = $gss_model->get_where_result_mapping_sketch(); $table1 = 'gss_mapping_sketch'; $where1 = array('project_id'=>$project_id ); $data['sketch'] = $gss_model->get_where_row($table1,$where1); $where_data = array('project_id'=>$project_id,'delete_status'=>'ACTIVE'); $table_site='gss_new_sites'; $data['site']=$gss_model->get_where_result($table_site,$where_data); $table_mapping='gss_mapping'; $data['site_id']=$gss_model->get_where_result($table_mapping,$where_data); $data['project'] = $gss_model->get_where_row($project_table,$where); $data['count'] = $gss_model->get_where_result($sites_table,$where); $data['orders'] = $gss_model->get_where_result($conversin_orders,$where); $where = array('delete_status'=>'ACTIVE','project_id'=>$project_id); $data['release_orders'] = $gss_model->get_where_result($project_table,$where); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/project_details',$data); } else { redirect('/'); } } public function new_sites_list() { $gss_model=new Gss_model(); $table = 'gss_new_sites'; $project_id = $_GET['project_id']; //echo $project_id; $order_by = "site_number"; $where = array( 'delete_status' => 'ACTIVE', 'project_id' => $project_id ); $result = $gss_model->get_where_result_orderby_asc($table,$where,$order_by); if($result) { $data = array(); foreach($result as $row) { $data[] = $row; } return $this->response->setJSON([$data]); } else { return $this->response->setJSON(['result'=>0]); } } public function new_projects_list() { $gss_model=new Gss_model(); $table = 'gss_new_projects'; $result = $gss_model->new_projects_list(); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } //Edit new project public function edit_new_project() { $gss_model=new Gss_model(); $table = 'gss_new_projects'; $project_id = $this->request->getPost('project_id'); $where = array('project_id'=>$project_id,'delete_status'=>'ACTIVE'); $result = $gss_model->edit_new_project($project_id); if($result) { return $this->response->setJSON(['project_details'=>$result,'result'=>1]); } else { return $this->response->setJSON(['result'=>0]); } } // public function update_new_project() // { // $gss_model = new Gss_model(); // $image = \Config\Services::image(); // $db = \Config\Database::connect(); // $table = 'gss_new_projects'; // $project_id = $this->request->getPost('project_id'); // $project_name = $this->request->getPost('project_name'); // $project_type = $this->request->getPost('project_type'); // $land_owner = $this->request->getPost('land_owner'); // $marketing = $this->request->getPost('marketing'); // $project_ownership = $this->request->getPost('project_ownership'); // $confirming_party_name = $this->request->getPost('confirming_party_name'); // $no_of_years = $this->request->getPost('no_of_years'); // $per_sq_ft = $this->request->getPost('per_sq_ft'); // $handled_by = $this->request->getPost('handled_by'); // $nick_name = $this->request->getPost('nick_name'); // $land_owner_address = $this->request->getPost('land_owner_address'); // // Determine project ownership // $p_name = $marketing == 'Confirming Party' ? $confirming_party_name : $project_ownership; // // Get the current timestamp for updated_at // $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); // $updated_at = $date->format('Y-m-d H:i:s'); // // Get file data from existing record // $where_file = ['project_id' => $project_id]; // $file_data = $gss_model->get_where_row($table, $where_file); // $release_order_image = $file_data->release_image; // $conversion_order_image = $file_data->conversion_image; // $approved_plan_image = $file_data->approval_image; // // Handle uploaded files // $approvedPlanImageFile = $this->request->getFile('approved_plan_image'); // if ($approvedPlanImageFile->isValid() && !$approvedPlanImageFile->hasMoved()) { // $approved_plan_image = $approvedPlanImageFile->getRandomName(); // } else { // $approved_plan_image = $approved_plan_image ?? ''; // } // // Handle conversion order image (multiple uploads) // if ($_FILES['conversion_order_image']['size'][0] != 0) { // $url = []; // for ($i = 0; $i < count($_FILES['conversion_order_image']['name']); $i++) { // $uploadPath = 'public/conversion_orders/'; // $stamp = time(); // $originalName = basename($_FILES['conversion_order_image']['name'][$i]); // $filename = $stamp . '_' . preg_replace('/\s+/', '_', $originalName); // $fullPath = $uploadPath . $filename; // $url[] = $filename; // if (!is_dir($uploadPath)) { // mkdir($uploadPath, 0775, true); // } // if (move_uploaded_file($_FILES['conversion_order_image']['tmp_name'][$i], $fullPath)) { // $image->withFile($fullPath)->resize(900, 900, true)->save($fullPath); // } else { // log_message('error', "Failed to upload: " . $_FILES['conversion_order_image']['name'][$i]); // } // } // } // // Handle release order image // $releaseOrderImageFile = $this->request->getFile('release_order_image'); // if ($releaseOrderImageFile->isValid() && !$releaseOrderImageFile->hasMoved()) { // $release_order_image = $releaseOrderImageFile->getRandomName(); // } else { // $release_order_image = $release_order_image ?? ''; // } // // Prepare data for database update // $data = [ // 'project_name' => $project_name, // 'nick_name' => $nick_name, // 'site_type' => $project_type, // 'land_owner_id' => $land_owner, // 'land_owner_address' => $land_owner_address, // 'marketing' => $marketing, // 'project_ownership' => $p_name, // 'no_of_years' => $no_of_years, // 'maintenance_per_sqft' => $per_sq_ft, // 'project_status' => 'ONGOING', // 'conversion_image' => $conversion_order_image, // 'release_image' => $release_order_image, // 'approval_image' => $approved_plan_image, // 'handled_by' => $handled_by, // 'delete_status' => 'ACTIVE', // 'updated_at' => $updated_at // ]; // // Check if project name already exists // $where_project = $file_data->project_name ?? null; // $where = ['delete_status' => 'ACTIVE', 'project_name !=' => $where_project]; // $numbers = $gss_model->get_where_result($table, $where); // $array = array_map(function($value) { return $value->project_name; }, $numbers); // if (in_array($project_name, $array)) { // return $this->response->setJSON(['result' => 2, 'message' => "Project already exists"]); // } else { // // Update project record // $where_id = ['project_id' => $project_id]; // if (!empty($_FILES['excel_file']['name'])) { // // Handle excel file upload // $file = $this->request->getFile('excel_file'); // if ($file->isValid()) { // $fileName = $file->getName(); // $ext = pathinfo($fileName, PATHINFO_EXTENSION); // if (in_array($ext, ['xlsx', 'xls'])) { // $tempPath = $file->getTempName(); // try { // $spreadsheet = IOFactory::load($tempPath); // $sheet = $spreadsheet->getSheet(0); // $highestRow = $sheet->getHighestRow(); // $highestColumn = $sheet->getHighestColumn(); // $allDataInSheet = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); // $arrayCount = count($allDataInSheet); // $site_table = 'gss_new_sites'; // foreach ($allDataInSheet as $row) { // // Insert the site data into the database // $site_number = trim($row["A"]); // $north_in_mtrs = sprintf("%.2f", trim($row["B"])); // $south_in_mtrs = sprintf("%.2f", trim($row["C"])); // $east_in_mtrs = sprintf("%.2f", trim($row["D"])); // $west_in_mtrs = sprintf("%.2f", trim($row["E"])); // $total_in_sqmtrs = sprintf("%.2f", trim($row["F"])); // $total_in_sqft = sprintf("%.2f", trim($row["G"])); // $east_facing = trim($row["H"]); // $west_facing = trim($row["I"]); // $north_facing = trim($row["J"]); // $south_facing = trim($row["K"]); // $status = trim($row["L"]); // $site_data = [ // 'project_id' => $project_id, // 'site_number' => $site_number, // 'north_in_mtrs' => $north_in_mtrs, // 'south_in_mtrs' => $south_in_mtrs, // 'east_in_mtrs' => $east_in_mtrs, // 'west_in_mtrs' => $west_in_mtrs, // 'total_in_sqmtrs' => $total_in_sqmtrs, // 'total_in_sqft' => $total_in_sqft, // 'east_facing' => $east_facing, // 'west_facing' => $west_facing, // 'north_facing' => $north_facing, // 'south_facing' => $south_facing, // 'status' => $status, // 'delete_status' => 'ACTIVE', // 'updated_at' => $updated_at // ]; // $gss_model->insert1($site_table, $site_data); // } // } catch (\PhpOffice\PhpSpreadsheet\Reader\Exception $e) { // die('Error loading file: ' . $e->getMessage()); // } // } // } // } // // Insert or update the conversion orders // if (isset($url)) { // $image_table = 'gss_project_conversion_orders'; // $gss_model->delete1($image_table, $where_file); // foreach ($url as $get_url) { // $get_urls = preg_replace('/\s+/', '_', $get_url); // $gallery_array = [ // 'project_id' => $project_id, // 'conversion_order' => $get_urls, // 'delete_status' => 'ACTIVE', // 'created_at' => $updated_at // ]; // $gss_model->insert1($image_table, $gallery_array); // } // } // // Perform update operation // $result = $gss_model->update1($table, $where_id, $data); // if ($db->affectedRows() > 0) { // return $this->response->setJSON(['result' => 1, 'message' => "Updated successfully"]); // } else { // return $this->response->setJSON(['result' => 0, 'message' => "Failed to update. Try again"]); // } // } // } public function add_more_site() { $gss_model = new Gss_model(); // adjust namespace if needed $request = \Config\Services::request(); $imageService = \Config\Services::image(); $project_id = $request->getPost('project_id'); $site_number = $request->getPost('site_number'); $north_in_mtrs = sprintf("%.2f", $request->getPost('north_in_mtrs')); $south_in_mtrs = sprintf("%.2f", $request->getPost('south_in_mtrs')); $east_in_mtrs = sprintf("%.2f", $request->getPost('east_in_mtrs')); $west_in_mtrs = sprintf("%.2f", $request->getPost('west_in_mtrs')); $total_in_sqmtrs = $request->getPost('total_in_sqmtrs'); $total_in_sqft = $request->getPost('total_in_sqft'); $east_facing = $request->getPost('east_facing'); $west_facing = $request->getPost('west_facing'); $north_facing = $request->getPost('north_facing'); $south_facing = $request->getPost('south_facing'); $status = $request->getPost('status'); $created_at = date('Y-m-d H:i:s'); // Handle file upload $file_name = ''; $file = $this->request->getFile('site_image'); if ($file && $file->isValid() && !$file->hasMoved()) { $uploadPath = FCPATH . 'project_uploads/9_and_11/'; if (!is_dir($uploadPath)) { mkdir($uploadPath, 0777, true); } $newName = time() . $file->getName(); $file->move($uploadPath, $newName); $file_name = $newName; // Resize the image $imageService->withFile($uploadPath . $file_name) ->resize(200, 150, true) ->save($uploadPath . $file_name); } // Check for duplicates $site_table = 'gss_new_sites'; $where = [ 'delete_status' => 'ACTIVE', 'site_number' => $site_number, 'project_id' => $project_id ]; $existing = $gss_model->get_where_result($site_table, $where); $existing_site_numbers = array_column($existing, 'site_number'); if (in_array($site_number, $existing_site_numbers)) { return $this->response->setJSON(['result' => 2, 'message' => "Site number already exists"]); } // Insert new site $data = [ 'project_id' => $project_id, 'site_number' => $site_number, 'north_in_mtrs' => $north_in_mtrs, 'south_in_mtrs' => $south_in_mtrs, 'east_in_mtrs' => $east_in_mtrs, 'west_in_mtrs' => $west_in_mtrs, 'total_in_sqmtrs' => $total_in_sqmtrs, 'total_in_sqft' => $total_in_sqft, 'east_facing' => $east_facing, 'west_facing' => $west_facing, 'north_facing' => $north_facing, 'south_facing' => $south_facing, 'status' => $status, 'site_image' => $file_name, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $insert = $gss_model->insert1($site_table, $data); if ($insert) { return $this->response->setJSON(['result' => 1, 'message' => "Site added successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong.. try again"]); } } // // public function add_booking_details() // { // $gss_model=new Gss_model(); // $customer_name = $this->request->getpost('customer_name'); // $relation = $this->request->getpost('relation'); // $fa_hu_name = $this->request->getpost('fa_hu_name'); // $email = $this->request->getpost('email'); // $alternative_email = $this->request->getpost('alternative_email'); // $mobile1 = $this->request->getpost('mobile1'); // $mobile2 = $this->request->getpost('mobile2'); // $office_no = $this->request->getpost('office_no'); // $bday = $this->request->getpost('bday'); // if($bday != "") // { // if (!empty($bday) && strtotime($bday) !== false) { // $date = new \DateTime($bday); // $bday = $date->format('Y-m-d'); // } else { // $bday = null; // } // } // $doa = $this->request->getpost('doa'); // if($doa != "") // { // if (!empty($doa) && strtotime($doa) !== false) { // $date = new \DateTime($doa); // $doa = $date->format('Y-m-d'); // } else { // $doa = null; // } // } // $address = $this->request->getpost('address'); // $id_name = $this->request->getpost('id_name'); // $id_no = $this->request->getpost('id_no'); // $nominee = $this->request->getpost('nominee'); // $nominee_con_no = $this->request->getpost('nominee_con_no'); // $reference = $this->request->getpost('reference'); // $web_portal = $this->request->getpost('web_portal'); // $logistics = $this->request->getpost('logistics'); // $associate = $this->request->getpost('associate'); // $subassociate = $this->request->getpost('subassociate'); // $source_type = $this->request->getpost('source_type'); // $source_bank_name = $this->request->getpost('source_bank_name'); // $project_id = $this->request->getpost('project_id'); // $site_number = $this->request->getpost('site_number'); // $reference_two = $this->request->getpost('reference_two'); // $logistics_two = $this->request->getpost('logistics_two'); // if($site_number[0] == 0) // { // $site_number = substr($site_number, 1); // } // else // { // $site_number = $this->request->getPost('site_number'); // } // $site_dimension = $this->request->getpost('site_dimension'); // $booking_date1 = $this->request->getpost('booking_date1'); // if($booking_date1 != "") // { // if (!empty($booking_date1) && strtotime($booking_date1) !== false) { // $date = new \DateTime($booking_date1); // $booking_date1 = $date->format('Y-m-d'); // } else { // $booking_date1 = null; // Handle invalid or empty date // } // } // $booking_amount_1 = $this->request->getpost('booking_amount1'); // $booking_amount1 = str_replace(',', '', $booking_amount_1); // $booking_date2 = $this->request->getpost('booking_date2'); // if($booking_date2 != "") // { // if (!empty($booking_date2) && strtotime($booking_date2) !== false) { // $date = new \DateTime($booking_date2); // $booking_date2 = $date->format('Y-m-d'); // } else { // $booking_date2 = null; // } // } // if($this->request->getpost('booking_amount2') == '') // { // $booking_amount2 = '0'; // } // else // { // $booking_amount_2 = $this->request->getpost('booking_amount2'); // $booking_amount2 = str_replace(',', '', $booking_amount_2); // } // $confirming_party1 =$this->request->getpost('owners_type1'); // $confirming_party2 =$this->request->getpost('owners_type2'); // $instal_due_date = $this->request->getpost('instal_due_date'); // if($instal_due_date != "") // { // if (!empty($instal_due_date) && strtotime($instal_due_date) !== false) { // $date = new \DateTime($instal_due_date); // $instal_due_date = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $instal_due_date = null; // Handle invalid or empty date // } // } // $instal_due_amounts = $this->request->getpost('instal_due_amount'); // $instal_due_amount = str_replace(',', '', $instal_due_amounts); // $reg_date_type = $this->request->getpost('reg_date_type'); // $reg_due_date = $this->request->getpost('reg_due_date'); // if($reg_due_date != "") // { // if (!empty($reg_due_date) && strtotime($reg_due_date) !== false) { // $date = new \DateTime($reg_due_date); // $reg_due_date = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $reg_due_date = null; // } // } // $reg_due_amounts = $this->request->getpost('reg_due_amount'); // $reg_due_amount = str_replace(',', '', $reg_due_amounts); // $sale_agree_date = $this->request->getpost('sale_agree_date'); // if($sale_agree_date != "") // { // if (!empty($sale_agree_date) && strtotime($sale_agree_date) !== false) { // $date = new \DateTime($sale_agree_date); // $sale_agree_date = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $sale_agree_date = null; // Handle invalid or empty date // } // } // $sale_agree_amounts = $this->request->getpost('sale_agree_amount'); // $sale_agree_amount = str_replace(',', '', $sale_agree_amounts); // $tsvs = $this->request->getpost('tsv'); // $tsv = str_replace(',', '', $tsvs); // $per_sqft = $this->request->getpost('per_sqft'); // $land_owner_rate = $this->request->getpost('land_owner_rate'); // $land_owner_amounts = $this->request->getpost('land_owner_amount'); // $land_owner_amount = str_replace(',', '', $land_owner_amounts); // $gss_rate = $this->request->getpost('gss_rate'); // $gss_amounts = $this->request->getpost('gss_amount'); // $gss_amount = str_replace(',', '', $gss_amounts); // $payment_type1 = $this->request->getpost('payment_type1'); // $check_no1 = ''; // $check_date1 = ''; // $bank_name1 = ''; // $vtr_no1 = ''; // $online_date1 = ''; // $dd_no1 = ''; // $dd_date1 = ''; // $dd_bank1 = ''; // $ref_no = ''; // $paytm_date = ''; // $upi_ref_no = ''; // $upi_date = ''; // if($payment_type1 == 'Cheque') // { // $check_no1 = $this->request->getpost('check_no1'); // $check_date1 = $this->request->getpost('check_date1'); // if($check_date1 != "") // { // if (!empty($check_date1) && strtotime($check_date1) !== false) { // $date = new \DateTime($check_date1); // $check_date1 = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $check_date1 = null; // Handle invalid or empty date // } // } // $bank_name1 = $this->request->getpost('bank_name1'); // } // else if($payment_type1 == 'Online Payment') // { // $vtr_no1 = $this->request->getpost('vtr_no1'); // $online_date1 = $this->request->getpost('online_date1'); // if($online_date1 != "") // { // if (!empty($online_date1) && strtotime($online_date1) !== false) { // $date = new \DateTime($online_date1); // $online_date1 = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $online_date1 = null; // Handle invalid or empty date // } // } // } // else if($payment_type1 == 'DD') // { // $dd_no1 = $this->request->getpost('dd_no1'); // $dd_date1 = $this->request->getpost('dd_date1'); // if($dd_date1 != "") // { // if (!empty($dd_date1) && strtotime($dd_date1) !== false) { // $date = new \DateTime($dd_date1); // $dd_date1 = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $dd_date1 = null; // Handle invalid or empty date // } // } // $dd_bank1 = $this->request->getpost('dd_bank1'); // } // else if($payment_type1 == 'Paytm Payment') // { // $ref_no = $this->request->getpost('ref_no'); // $paytm_date = $this->request->getpost('paytm_date'); // if($paytm_date != "") // { // if (!empty($paytm_date) && strtotime($paytm_date) !== false) { // $date = new \DateTime($paytm_date); // $paytm_date = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $paytm_date = null; // Handle invalid or empty date // } // } // } // else if($payment_type1 == 'UPI Payment') // { // $upi_ref_no = $this->request->getpost('upi_ref_no'); // $upi_date = $this->request->getpost('upi_date'); // if($upi_date != "") // { // if (!empty($upi_date) && strtotime($upi_date) !== false) { // $date = new \DateTime($upi_date); // $upi_date = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $upi_date = null; // Handle invalid or empty date // } // } // } // $payment_type2 = $this->request->getpost('payment_type2'); // $check_no2 = ''; // $check_date2 = ''; // $bank_name2 = ''; // $vtr_no2 = ''; // $online_date2 = ''; // $dd_no2 = ''; // $dd_date2 = ''; // $dd_bank2 = ''; // $ref_no1 =''; // $paytm_date1 =''; // $upi_ref_no1 =''; // $upi_date1 =''; // if($payment_type2 == 'Cheque') // { // $check_no2 = $this->request->getpost('check_no2'); // $check_date2 = $this->request->getpost('check_date2'); // if($check_date2 != "") // { // if (!empty($check_date2) && strtotime($check_date2) !== false) { // $date = new \DateTime($check_date2); // $check_date2 = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $check_date2 = null; // Handle invalid or empty date // } // } // $bank_name2 = $this->request->getpost('bank_name2'); // } // else if($payment_type2 == 'Online Payment') // { // $vtr_no2 = $this->request->getpost('vtr_no2'); // $online_date2 = $this->request->getpost('online_date2'); // if($online_date2 != "") // { // if (!empty($online_date2) && strtotime($online_date2) !== false) { // $date = new \DateTime($online_date2); // $online_date2 = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $online_date2 = null; // Handle invalid or empty date // } // } // } // else if($payment_type2 == 'DD') // { // $dd_no2 = $this->request->getpost('dd_no2'); // $dd_date2 = $this->request->getpost('dd_date2'); // if($dd_date2 != "") // { // if (!empty($dd_date2) && strtotime($dd_date2) !== false) { // $date = new \DateTime($dd_date2); // $dd_date2 = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $dd_date2 = null; // Handle invalid or empty date // } // } // $dd_bank2 = $this->request->getpost('dd_bank2'); // } // else if($payment_type2 == 'Paytm Payment') // { // $ref_no1 = $this->request->getpost('ref_no1'); // $paytm_date1 = $this->request->getpost('paytm_date1'); // if($paytm_date1 != "") // { // if (!empty($paytm_date1) && strtotime($paytm_date1) !== false) { // $date = new \DateTime($paytm_date1); // $paytm_date1 = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $paytm_date1 = null; // Handle invalid or empty date // } // } // } // else if($payment_type2 == 'UPI Payment') // { // $upi_ref_no1 = $this->request->getpost('upi_ref_no1'); // $upi_date1 = $this->request->getpost('upi_date1'); // if($upi_date1 != "") // { // if (!empty($upi_date1) && strtotime($upi_date1) !== false) { // $date = new \DateTime($upi_date1); // $upi_date1 = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format // } else { // $upi_date1 = null; // Handle invalid or empty date // } // } // } // $load = $image = \Config\Services::image(); // $id_scan = ""; // $application_scan = ""; // if($_FILES) // { // if(empty($_FILES['id_scan']['name'])) // { // $id_scan = ""; // } // else // { // $target='public/booking_uploads/'; // $target.=time().$_FILES['id_scan']['name']; // $id_scan=time().$_FILES['id_scan']['name']; // $image=$target; // $target1 = preg_replace('/\s+/', '_', $target); // move_uploaded_file($_FILES['id_scan']['tmp_name'],$target1); // $config['source_image']=$target1; // $config['maintain_ratio']=TRUE; // $image = \Config\Services::image(); // $image->withFile($target) // ->resize(200, 150, true) // Resize the image while maintaining the aspect ratio // ->save($target); // } // if(!empty($id_scan)) // { // $id_scans = preg_replace('/\s+/', '_', $id_scan); // } // else // { // $id_scans = ""; // } // if(empty($_FILES['application_scan']['name'])) // { // $application_scan = ""; // } // else // { // $target='public/booking_uploads/'; // $target.=time().$_FILES['application_scan']['name']; // $application_scan=time().$_FILES['application_scan']['name']; // $image=$target; // $target1 = preg_replace('/\s+/', '_', $target); // move_uploaded_file($_FILES['application_scan']['tmp_name'],$target1); // $config['source_image']=$target1; // $config['maintain_ratio']=TRUE; // $image = \Config\Services::image(); // $image->withFile($target) // ->resize(200, 150, true) // Resize the image while maintaining the aspect ratio // ->save($target); // } // if(!empty($application_scan)) // { // $application_scans = preg_replace('/\s+/', '_', $application_scan); // } // else // { // $application_scans = ""; // } // } // $khata_status = $this->request->getpost('khata_status'); // $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); // $created_at = $date->format('Y-m-d H:i:s'); // $booking_data = array( // 'project_id' => $project_id, // 'customer_name' => $customer_name, // 'relation' => $relation, // 'father_or_husband' => $fa_hu_name, // 'email' => $email, // 'alternative_email' => $alternative_email, // 'mobile1' => $mobile1, // 'mobile2' => $mobile2, // 'dob' => $bday, // 'doa' => $doa, // 'address' => $address, // 'nominee_name' => $nominee, // 'nominee_contact' => $nominee_con_no, // 'office_number' => $office_no, // 'idproof_name' => $id_name, // 'idproof_number' => $id_no, // 'idproof_image' => $id_scans, // 'webportal' => $web_portal, // 'logistics' => $logistics, // 'reference' => $reference, // 'associate' => $associate, // 'subassociate' => $subassociate, // 'reference_two' => $reference_two, // 'logistics_two' => $logistics_two, // 'source_type' => $source_type, // 'source_bank_name' => $source_bank_name, // 'khata_status' => $khata_status, // 'delete_status' => 'ACTIVE', // 'created_at' => $created_at // ); // //print_r($booking_data);die(); // $total = 0; // if($instal_due_amount == 0 || $instal_due_amount == "") // { // $total = (float)$booking_amount1 + (float)$booking_amount2 + (float)$reg_due_amount + (float)$sale_agree_amount; // } // else // { // $total = $booking_amount1 + $booking_amount2 + $instal_due_amount + $reg_due_amount + $sale_agree_amount; // } // if($total > $tsv || $total < $tsv) // { // return $this->response->setJSON(['result'=>3,'message'=>"Not matching TSV"]); // } // else if($payment_type1 == "") // { // return $this->response->setJSON(['result'=>4,'message'=>"Choose atleaset one payment type"]); // } // else // { // $booking_table = 'gss_bookings'; // $detail_table = 'gss_booking_details'; // $instal_table = 'gss_booking_installments'; // $where = array('delete_status'=>'ACTIVE','project_id'=>$project_id); // $sites = $gss_model->get_where_result($detail_table,$where); // $array = array(); // foreach($sites as $value) // { // array_push($array, $value->site_number); // } // if(in_array($site_number,$array)) // { // $order_by = 'booking_id'; // $where1 = array('delete_status'=>'ACTIVE','project_id'=>$project_id,'site_number'=>$site_number); // $check = $gss_model->get_where_orderby_row($detail_table,$where1,$order_by); // $where2 = array('delete_status'=>'ACTIVE','booking_id'=>$check->booking_id); // $status = $gss_model->get_where_orderby_row($booking_table,$where2,$order_by); // $result = $gss_model->insert1($booking_table,$booking_data); // if($result) // { // $detail_data = array( // 'booking_id' => $result, // 'project_id' => $project_id, // 'booking_date1' => $booking_date1, // 'booking_amount1' => $booking_amount1, // 'booking_date2' => $booking_date2, // 'booking_amount2' => $booking_amount2, // 'booking_payment_type' => $payment_type1, // 'booking_payment_type2' => $payment_type2, // 'confirming_party1' =>$confirming_party1, // 'confirming_party2' =>$confirming_party2, // 'check_no' => $check_no1, // 'check_date' => $check_date1, // 'bank_name' => $bank_name1, // 'vtr_no' => $vtr_no1, // 'online_date' => $online_date1, // 'dd_no' => $dd_no1, // 'dd_date' => $dd_date1, // 'dd_bank' => $dd_bank1, // 'paytm_ref_no' =>$ref_no, // 'paytm_online_date' =>$paytm_date, // 'upi_ref_no' =>$upi_ref_no, // 'upi_online_date' =>$upi_date, // 'check_no2' => $check_no2, // 'check_date2' => $check_date2, // 'bank_name2' => $bank_name2, // 'vtr_no2' => $vtr_no2, // 'online_date2' => $online_date2, // 'dd_no2' => $dd_no2, // 'dd_date2' => $dd_date2, // 'dd_bank2' => $dd_bank2, // 'paytm_ref_no2' =>$ref_no1, // 'paytm_online_date2' =>$paytm_date1, // 'upi_ref_no2' =>$upi_ref_no1, // 'upi_online_date2' =>$upi_date1, // 'tsv' => $tsv, // 'tsv_per_sft_rs' => $per_sqft, // 'land_owner_rate' => $land_owner_rate, // 'land_owner_amount' => $land_owner_amount, // 'gss_rate' => $gss_rate, // 'gss_amount' => $gss_amount, // 'sales_agreement_due_date' => $sale_agree_date, // 'sales_agreement_due_amount' => $sale_agree_amount, // 'reg_date_type' => $reg_date_type, // 'registration_due_date' => $reg_due_date, // 'registration_due_amount' => $reg_due_amount, // 'site_number' => $site_number, // 'dimension' => $site_dimension, // 'application_scan' => $application_scans, // 'delete_status' => 'ACTIVE', // 'created_at' => $created_at // ); // $detail_result = $gss_model->insert1($detail_table,$detail_data); // if($detail_result) // { // $result1 = $gss_model->booking_status($detail_result); // if($result1) // { // $data=array('site_status'=>'BOOKED'); // $project_table = 'gss_new_sites'; // $where=array('site_number'=>$result1->site_number,'delete_status'=>'ACTIVE'); // $resulted = $gss_model->update1($where,$project_table,$data); // } // $db = \Config\Database::connect(); // $this->session->set_userdata('booking_id',$result); // $instal_data = array( // 'booking_id' => $result, // 'booking_detal_id' => $detail_result, // 'installment_due_date' => $instal_due_date, // 'installment_due_amount' => $instal_due_amount, // 'payment_mode' => $payment_type1 // ); // $instal_result = $gss_model->insert1($instal_table,$instal_data); // $where_user = array('booking_id'=>$result); // $user_data = $gss_model->get_where_row($booking_table,$where_user); // $booking_receipt = $gss_model->booking_receipt_site_data($result); // $todays_date = $date->format('Y-m-d'); // $received = $booking_amount1 + $booking_amount2; // $mobile1 = json_decode($user_data->mobile1); // //$number = rtrim(implode(',', $mobile1), ','); // $number = $mobile1; // $balance = $tsv - $received; // $total = $received + $balance; // echo json_encode(array( // 'result' => 1, // 'booking_id' => $result, // 'user_data' => $user_data, // 'todays_date' => $todays_date, // 'booking_receipt' => $booking_receipt, // 'received' => $received, // 'number' => $number, // 'balance' => $balance, // 'total' => $total, // 'message' => "Site booked successfully" // )); // } // else // { // return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); // } // } // else // { // return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); // } // } // else // { // $site_table = "gss_new_sites"; // $where = ['delete_status'=>'ACTIVE','project_id'=>$project_id]; // $site_numbers = $gss_model->get_where_result($site_table,$where); // $array = array(); // foreach($site_numbers as $value) // { // array_push($array, $value->site_number); // } // if(!(in_array($site_number,$array))) // { // return $this->response->setJSON(['result'=>2,'message'=>"Site number does not exist"]); // } // else // { // $result = $gss_model->insert1($booking_table,$booking_data); // if($result) // { // $detail_data = array( // 'booking_id' => $result, // 'project_id' => $project_id, // 'booking_date1' => $booking_date1, // 'booking_amount1' => $booking_amount1, // 'booking_date2' => $booking_date2, // 'booking_amount2' => $booking_amount2, // 'booking_payment_type' => $payment_type1, // 'confirming_party1' =>$confirming_party1, // 'confirming_party2' =>$confirming_party2, // 'check_no' => $check_no1, // 'check_date' => $check_date1, // 'bank_name' => $bank_name1, // 'vtr_no' => $vtr_no1, // 'online_date' => $online_date1, // 'dd_no' => $dd_no1, // 'dd_date' => $dd_date1, // 'dd_bank' => $dd_bank1, // 'paytm_ref_no' =>$ref_no, // 'paytm_online_date' =>$paytm_date, // 'upi_ref_no' =>$upi_ref_no, // 'upi_online_date' =>$upi_date, // 'booking_payment_type2' => $payment_type2, // 'check_no2' => $check_no2, // 'check_date2' => $check_date2, // 'bank_name2' => $bank_name2, // 'vtr_no2' => $vtr_no2, // 'dd_no2' => $dd_no2, // 'dd_date2' => $dd_date2, // 'dd_bank2' => $dd_bank2, // 'online_date2' => $online_date2, // 'paytm_ref_no2' =>$ref_no1, // 'paytm_online_date2' =>$paytm_date1, // 'upi_ref_no2' =>$upi_ref_no1, // 'upi_online_date2' =>$upi_date1, // 'tsv' => $tsv, // 'tsv_per_sft_rs' => $per_sqft, // 'land_owner_rate' => $land_owner_rate, // 'land_owner_amount' => $land_owner_amount, // 'gss_rate' => $gss_rate, // 'gss_amount' => $gss_amount, // 'sales_agreement_due_date' => $sale_agree_date, // 'sales_agreement_due_amount' => $sale_agree_amount, // 'reg_date_type' => $reg_date_type, // // 'registration_due_date' => $reg_due_date, // 'registration_due_amount' => $reg_due_amount, // 'site_number' => $site_number, // 'dimension' => $site_dimension, // 'application_scan' => $application_scans, // 'delete_status' => 'ACTIVE', // 'created_at' => $created_at // ); // $detail_result = $gss_model->insert1($detail_table,$detail_data); // if($detail_result) // { // $result1 = $gss_model->booking_status($detail_result); // if($result1) // { // $data=array('site_status'=>'BOOKED'); // $project_table = 'gss_new_sites'; // $where=array('site_number'=>$result1->site_number,'delete_status'=>'ACTIVE'); // $resulted = $gss_model->update1($where,$project_table,$data); // } // $this->session->set_userdata('booking_id',$result); // $instal_data = array( // 'booking_id' => $result, // 'booking_detal_id' => $detail_result, // 'installment_due_date' => $instal_due_date, // 'installment_due_amount' => $instal_due_amount, // 'payment_mode' => $payment_type2 // ); // $instal_result = $gss_model->insert1($instal_table,$instal_data); // $where_user = array('booking_id'=>$result); // $user_data = $gss_model->get_where_row($booking_table,$where_user); // $booking_receipt = $gss_model->booking_receipt_site_data($result); // $todays_date = $date->format('Y-m-d'); // $received = $booking_amount1 + $booking_amount2; // if($user_data) // { // $mobile2 = json_decode($user_data->mobile2); // $number = $mobile2; // $balance = $tsv - $received; // $total = $received + $balance; // echo json_encode(array( // 'result' => 1, // 'booking_id' => $result, // 'user_data' => $user_data, // 'todays_date' => $todays_date, // 'booking_receipt' => $booking_receipt, // 'received' => $received, // 'number' => $number, // 'balance' => $balance, // 'total' => $total, // 'message' => "Site booked successfully" // )); // } // else // { // return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); // } // } // else // { // return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); // } // } // } // } // } // } public function add_booking_details() { $customer_name = $this->request->getPost('customer_name'); $relation = $this->request->getPost('relation'); $fa_hu_name = $this->request->getPost('fa_hu_name'); $email = $this->request->getPost('email'); $alternative_email = $this->request->getPost('alternative_email'); $mobile1 = $this->request->getPost('mobile1'); $mobile2 = $this->request->getPost('mobile2'); $office_no = $this->request->getPost('office_no'); $bday = $this->request->getPost('bday'); if (!empty($bday)) { $date = new \DateTime($bday); $bday = $date->format('Y-m-d'); } $doa = $this->request->getPost('doa'); if (!empty($doa)) { $date = new \DateTime($doa); $doa = $date->format('Y-m-d'); } $address = $this->request->getPost('address'); $id_name = $this->request->getPost('id_name'); $id_no = $this->request->getPost('id_no'); $nominee = $this->request->getPost('nominee'); $nominee_con_no = $this->request->getPost('nominee_con_no'); $reference = $this->request->getPost('reference'); $web_portal = $this->request->getPost('web_portal'); $logistics = $this->request->getPost('logistics'); $associate = $this->request->getPost('associate'); $subassociate = $this->request->getPost('subassociate'); $source_type = $this->request->getPost('source_type'); $source_bank_name = $this->request->getPost('source_bank_name'); $project_id = $this->request->getPost('project_id'); $site_number = $this->request->getPost('site_number'); $reference_two = $this->request->getPost('reference_two'); $logistics_two = $this->request->getPost('logistics_two'); if (!empty($site_number) && $site_number[0] == '0') { $site_number = substr($site_number, 1); } $site_dimension = $this->request->getPost('site_dimension'); $booking_date1 = $this->request->getPost('booking_date1'); if (!empty($booking_date1)) { $date = new \DateTime($booking_date1); $booking_date1 = $date->format('Y-m-d'); } $booking_amount_1 = $this->request->getPost('booking_amount1'); $booking_amount1 = str_replace(',', '', $booking_amount_1); $booking_date2 = $this->request->getPost('booking_date2'); if (!empty($booking_date2)) { $date = new \DateTime($booking_date2); $booking_date2 = $date->format('Y-m-d'); } $booking_amount2_raw = $this->request->getPost('booking_amount2'); if ($booking_amount2_raw === '' || $booking_amount2_raw === null) { $booking_amount2 = '0'; } else { $booking_amount2 = str_replace(',', '', $booking_amount2_raw); } if (!empty($instal_due_date)) { $date = new \DateTime($instal_due_date); $instal_due_date = $date->format('Y-m-d'); } $instal_due_amounts = $this->request->getPost('instal_due_amount'); $instal_due_amount = str_replace(',', '', $instal_due_amounts); $reg_date_type = $this->request->getPost('reg_date_type'); $reg_due_date = $this->request->getPost('reg_due_date'); if(!empty($reg_due_date)) { $date = new DateTime($reg_due_date); $reg_due_date = $date->format('Y-m-d'); } $reg_due_amounts = $this->request->getPost('reg_due_amount'); $reg_due_amount = str_replace(',', '', $reg_due_amounts); $sale_agree_date = $this->request->getPost('sale_agree_date'); if( !empty($sale_agree_date)) { $date = new DateTime($sale_agree_date); $sale_agree_date = $date->format('Y-m-d'); } $sale_agree_amounts = $this->request->getPost('sale_agree_amount'); $sale_agree_amount = str_replace(',', '', $sale_agree_amounts); $tsvs = $this->request->getPost('tsv'); $tsv = str_replace(',', '', $tsvs); $per_sqft = $this->request->getPost('per_sqft'); $land_owner_rate = $this->request->getPost('land_owner_rate'); $land_owner_amounts = $this->request->getPost('land_owner_amount'); $land_owner_amount = str_replace(',', '', $land_owner_amounts); $gss_rate = $this->request->getPost('gss_rate'); $gss_amounts = $this->request->getPost('gss_amount'); $gss_amount = str_replace(',', '', $gss_amounts); $payment_type1 = $this->request->getPost('payment_type1'); $check_no1 = ''; $check_date1 = ''; $bank_name1 = ''; $vtr_no1 = ''; $online_date1 = ''; $dd_no1 = ''; $dd_date1 = ''; $dd_bank1 = ''; $ref_no = ''; $paytm_date = ''; $upi_ref_no = ''; $upi_date = ''; if ($payment_type1 == 'Cheque') { $check_no1 = $this->request->getPost('check_no1'); $check_date1 = $this->request->getPost('check_date1'); if (!empty($check_date1)) { $date = new \DateTime($check_date1); $check_date1 = $date->format('Y-m-d'); } $bank_name1 = $this->request->getPost('bank_name1'); } else if ($payment_type1 == 'Online Payment') { $vtr_no1 = $this->request->getPost('vtr_no1'); $online_date1 = $this->request->getPost('online_date1'); if (!empty($online_date1)) { $date = new \DateTime($online_date1); $online_date1 = $date->format('Y-m-d'); } } else if ($payment_type1 == 'DD') { $dd_no1 = $this->request->getPost('dd_no1'); $dd_date1 = $this->request->getPost('dd_date1'); if (!empty($dd_date1)) { $date = new \DateTime($dd_date1); $dd_date1 = $date->format('Y-m-d'); } $dd_bank1 = $this->request->getPost('dd_bank1'); } else if ($payment_type1 == 'Paytm Payment') { $ref_no = $this->request->getPost('ref_no'); $paytm_date = $this->request->getPost('paytm_date'); if (!empty($paytm_date)) { $date = new \DateTime($paytm_date); $paytm_date = $date->format('Y-m-d'); } } else if ($payment_type1 == 'UPI Payment') { $upi_ref_no = $this->request->getPost('upi_ref_no'); $upi_date = $this->request->getPost('upi_date'); if (!empty($upi_date)) { $date = new \DateTime($upi_date); $upi_date = $date->format('Y-m-d'); } } $payment_type2 = $this->request->getPost('payment_type2'); $check_no2 = ''; $check_date2 = ''; $bank_name2 = ''; $vtr_no2 = ''; $online_date2 = ''; $dd_no2 = ''; $dd_date2 = ''; $dd_bank2 = ''; $ref_no1 =''; $paytm_date1 =''; $upi_ref_no1 =''; $upi_date1 =''; if ($payment_type2 == 'Cheque') { $check_no2 = $this->request->getPost('check_no2'); $check_date2 = $this->request->getPost('check_date2'); if (!empty($check_date2)) { $date = new \DateTime($check_date2); $check_date2 = $date->format('Y-m-d'); } $bank_name2 = $this->request->getPost('bank_name2'); } else if ($payment_type2 == 'Online Payment') { $vtr_no2 = $this->request->getPost('vtr_no2'); $online_date2 = $this->request->getPost('online_date2'); if (!empty($online_date2)) { $date = new \DateTime($online_date2); $online_date2 = $date->format('Y-m-d'); } } else if ($payment_type2 == 'DD') { $dd_no2 = $this->request->getPost('dd_no2'); $dd_date2 = $this->request->getPost('dd_date2'); if (!empty($dd_date2)) { $date = new \DateTime($dd_date2); $dd_date2 = $date->format('Y-m-d'); } $dd_bank2 = $this->request->getPost('dd_bank2'); } else if ($payment_type2 == 'Paytm Payment') { $ref_no1 = $this->request->getPost('ref_no1'); $paytm_date1 = $this->request->getPost('paytm_date1'); if (!empty($paytm_date1)) { $date = new \DateTime($paytm_date1); $paytm_date1 = $date->format('Y-m-d'); } } else if ($payment_type2 == 'UPI Payment') { $upi_ref_no1 = $this->request->getPost('upi_ref_no1'); $upi_date1 = $this->request->getPost('upi_date1'); if (!empty($upi_date1)) { $date = new \DateTime($upi_date1); $upi_date1 = $date->format('Y-m-d'); } } $id_scans = ""; $application_scans = ""; if ($this->request->getFiles()) { // Upload ID Scan $idScanFile = $this->request->getFile('id_scan'); if ($idScanFile && $idScanFile->isValid() && !$idScanFile->hasMoved()) { $newName = time() . preg_replace('/\s+/', '_', $idScanFile->getName()); $uploadPath = FCPATH . 'booking_uploads/'; $idScanFile->move($uploadPath, $newName); $id_scans = $newName; } $appScanFile = $this->request->getFile('application_scan'); if ($appScanFile && $appScanFile->isValid() && !$appScanFile->hasMoved()) { $newName = time() . preg_replace('/\s+/', '_', $appScanFile->getName()); $uploadPath = FCPATH . 'booking_uploads/'; $appScanFile->move($uploadPath, $newName); $application_scans = $newName; } } $khata_status = $this->request->getPost('khata_status'); $created_at = date('Y-m-d H:i:s'); $booking_data =[ 'project_id' => $project_id, 'customer_name' => $customer_name, 'relation' => $relation, 'father_or_husband' => $fa_hu_name, 'email' => $email, 'alternative_email' => $alternative_email, 'mobile1' => $mobile1, 'mobile2' => $mobile2, 'dob' => $bday, 'doa' => $doa, 'address' => $address, 'nominee_name' => $nominee, 'nominee_contact' => $nominee_con_no, 'office_number' => $office_no, 'idproof_name' => $id_name, 'idproof_number' => $id_no, 'idproof_image' => $id_scans, 'webportal' => $web_portal, 'logistics' => $logistics, 'reference' => $reference, 'associate' => $associate, 'subassociate' => $subassociate, 'reference_two' => $reference_two, 'logistics_two' => $logistics_two, 'source_type' => $source_type, 'source_bank_name' => $source_bank_name, 'khata_status' => $khata_status, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $total = 0; $instal_due_amount = ($instal_due_amount == "" || $instal_due_amount == null) ? 0 : $instal_due_amount; $total = $booking_amount1 + $booking_amount2 + $reg_due_amount + $sale_agree_amount + $instal_due_amount; //corrected if ($total != $tsv) { return $this->response->setJSON([ 'result' => 3, 'message' => "Not matching TSV" ]); } elseif (empty($payment_type1)) { return $this->response->setJSON([ 'result' => 4, 'message' => "Choose at least one payment type" ]); } else { $gss_model=new Gss_model(); $booking_table = 'gss_bookings'; $detail_table = 'gss_booking_details'; $instal_table = 'gss_booking_installments'; $where =['delete_status'=>'ACTIVE','project_id'=>$project_id]; $sites = $gss_model->get_where_result($detail_table,$where); $array = array(); foreach ($sites as $value) { array_push($array, $value->site_number); } //corrected if (in_array($site_number, $array)) { $order_by = ['id' => 'DESC']; // $where1 = ['delete_status' => 'ACTIVE', 'project_id' => $project_id, 'site_number' => $site_number]; $where1 = ['delete_status'=>'ACTIVE','project_id'=>$project_id,'site_number'=>$site_number]; $check = $gss_model->get_where_result($detail_table,$where1,$order_by); $where2 = ['delete_status' => 'ACTIVE', 'booking_id' => $check['booking_id']]; $status = $gss_model->get_where_result($booking_table,$where2,$order_by); $result = $gss_model->insert1($booking_table,$booking_data); if($result) { $detail_data = [ 'booking_id' => $result, 'project_id' => $project_id, 'booking_date1' => $booking_date1, 'booking_amount1' => $booking_amount1, 'booking_date2' => $booking_date2, 'booking_amount2' => $booking_amount2, 'booking_payment_type' => $payment_type1, 'booking_payment_type2' => $payment_type2, 'confirming_party1' =>$confirming_party1, 'confirming_party2' =>$confirming_party2, 'check_no' => $check_no1, 'check_date' => $check_date1, 'bank_name' => $bank_name1, 'vtr_no' => $vtr_no1, 'online_date' => $online_date1, 'dd_no' => $dd_no1, 'dd_date' => $dd_date1, 'dd_bank' => $dd_bank1, 'paytm_ref_no' =>$ref_no, 'paytm_online_date' =>$paytm_date, 'upi_ref_no' =>$upi_ref_no, 'upi_online_date' =>$upi_date, 'check_no2' => $check_no2, 'check_date2' => $check_date2, 'bank_name2' => $bank_name2, 'vtr_no2' => $vtr_no2, 'online_date2' => $online_date2, 'dd_no2' => $dd_no2, 'dd_date2' => $dd_date2, 'dd_bank2' => $dd_bank2, 'paytm_ref_no2' =>$ref_no1, 'paytm_online_date2' =>$paytm_date1, 'upi_ref_no2' =>$upi_ref_no1, 'upi_online_date2' =>$upi_date1, 'tsv' => $tsv, 'tsv_per_sft_rs' => $per_sqft, 'land_owner_rate' => $land_owner_rate, 'land_owner_amount' => $land_owner_amount, 'gss_rate' => $gss_rate, 'gss_amount' => $gss_amount, 'sales_agreement_due_date' => $sale_agree_date, 'sales_agreement_due_amount' => $sale_agree_amount, 'reg_date_type' => $reg_date_type, 'registration_due_date' => $reg_due_date, 'registration_due_amount' => $reg_due_amount, 'site_number' => $site_number, 'dimension' => $site_dimension, 'application_scan' => $application_scans, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $detail_result = $gss_model->insert1($detail_table,$detail_data); if($detail_result) { $result1 = $gss_model->booking_status($detail_result); if($result1) { $data=['site_status'=>'BOOKED']; $project_table = 'gss_new_sites'; $where=['site_number'=>$result1->site_number,'delete_status'=>'ACTIVE']; $resulted = $gss_model->update1($project_table,$where,$data); } session()->set('booking_id',$result); $instal_data =[ 'booking_id' => $result, 'booking_detal_id' => $detail_result, 'installment_due_date' => $instal_due_date, 'installment_due_amount' => $instal_due_amount, 'payment_mode' => $payment_type1 ]; $instal_result = $gss_model->insert1($instal_table,$instal_data); $where_user = ['booking_id'=>$result]; $user_data = $gss_model->get_where_row($booking_table,$where_user); $booking_receipt = $gss_model->booking_receipt_site_data($result); $todays_date = $date->format('Y-m-d'); $received = $booking_amount1 + $booking_amount2; $mobile1 = json_decode($user_data->mobile1); $number = $mobile1; $balance = $tsv - $received; $total = $received + $balance; return $this->response->setJSON([ 'result' => 1, 'booking_id' => $result, 'user_data' => $user_data, 'todays_date' => $todays_date, 'booking_receipt' => $booking_receipt, 'received' => $received, 'number' => $number, 'balance' => $balance, 'total' => $total, 'message' => "Site booked successfully" ]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); } } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); } } else{ $site_table = "gss_new_sites"; $where = ['delete_status'=>'ACTIVE','project_id'=>$project_id]; $site_numbers = $gss_model->get_where_result($site_table,$where); $array = array(); foreach($site_numbers as $value) { array_push($array, $value->site_number); } if(!(in_array($site_number,$array))) { return $this->response->setJSON(['result'=>2,'message'=>"Site number does not exist"]); } else { $result = $gss_model->insert1($booking_table,$booking_data); if($result) { $detail_data = [ 'booking_id' => $result, 'project_id' => $project_id, 'booking_date1' => $booking_date1, 'booking_amount1' => $booking_amount1, 'booking_date2' => $booking_date2, 'booking_amount2' => $booking_amount2, 'booking_payment_type' => $payment_type1, 'confirming_party1' =>$confirming_party1, 'confirming_party2' =>$confirming_party2, 'check_no' => $check_no1, 'check_date' => $check_date1, 'bank_name' => $bank_name1, 'vtr_no' => $vtr_no1, 'online_date' => $online_date1, 'dd_no' => $dd_no1, 'dd_date' => $dd_date1, 'dd_bank' => $dd_bank1, 'paytm_ref_no' =>$ref_no, 'paytm_online_date' =>$paytm_date, 'upi_ref_no' =>$upi_ref_no, 'upi_online_date' =>$upi_date, 'booking_payment_type2' => $payment_type2, 'check_no2' => $check_no2, 'check_date2' => $check_date2, 'bank_name2' => $bank_name2, 'vtr_no2' => $vtr_no2, 'dd_no2' => $dd_no2, 'dd_date2' => $dd_date2, 'dd_bank2' => $dd_bank2, 'online_date2' => $online_date2, 'paytm_ref_no2' =>$ref_no1, 'paytm_online_date2' =>$paytm_date1, 'upi_ref_no2' =>$upi_ref_no1, 'upi_online_date2' =>$upi_date1, 'tsv' => $tsv, 'tsv_per_sft_rs' => $per_sqft, 'land_owner_rate' => $land_owner_rate, 'land_owner_amount' => $land_owner_amount, 'gss_rate' => $gss_rate, 'gss_amount' => $gss_amount, 'sales_agreement_due_date' => $sale_agree_date, 'sales_agreement_due_amount' => $sale_agree_amount, 'reg_date_type' => $reg_date_type, 'registration_due_date' => $reg_due_date, 'registration_due_amount' => $reg_due_amount, 'site_number' => $site_number, 'dimension' => $site_dimension, 'application_scan' => $application_scans, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $detail_result = $gss_model->insert1($detail_table,$detail_data); if($detail_result) { $result1 = $gss_model->booking_status($detail_result); if($result1) { $data=['site_status'=>'BOOKED']; $project_table = 'gss_new_sites'; $where=['site_number'=>$result1->site_number,'delete_status'=>'ACTIVE']; $resulted = $gss_model->update($where,$project_table,$data); } session()->set('booking_id',$result); $instal_data = [ 'booking_id' => $result, 'booking_detal_id' => $detail_result, 'installment_due_date' => $instal_due_date, 'installment_due_amount' => $instal_due_amount, 'payment_mode' => $payment_type2 ]; $instal_result = $gss_model->insert($instal_table,$instal_data); $where_user = ['booking_id'=>$result]; $user_data = $gss_model->get_where_row($booking_table,$where_user); $booking_receipt = $gss_model->booking_receipt_site_data($result); $todays_date = $date('Y-m-d'); $received = $booking_amount1 + $booking_amount2; if($user_data) { $mobile2 = json_decode($user_data->mobile2); $number = $mobile2; $balance = $tsv - $received; $total = $received + $balance; return $this->response->setJSON([ 'result' => 1, 'booking_id' => $result, 'user_data' => $user_data, 'todays_date' => $todays_date, 'booking_receipt' => $booking_receipt, 'received' => $received, 'number' => $number, 'balance' => $balance, 'total' => $total, 'message' => "Site booked successfully" ]); } else { echo json_encode(array('result'=>0,'message'=>"Something went wrong.. try again")); } } else { echo json_encode(array('result'=>0,'message'=>"Something went wrong.. try again")); } } } } // ----------------------- } // ------------------ } public function booking_details() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $table = 'gss_bookings'; $broker_table = 'gss_brokers'; $instal_table = 'gss_booking_installments'; $booking_id = service('uri')->getSegment(2); $data['site_result'] = $gss_model->user_site_booking_details1($booking_id); $site_result = $gss_model->user_site_booking_details1($booking_id); $where = array('booking_id'=>$booking_id,'delete_status'=>'ACTIVE'); $data['instal_result'] = $gss_model->get_where_row($instal_table,$where); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); // print_r($data);die(); return view('admin/site_booking_details',$data); } else { redirect('/'); } } //Booking details public function user_site_booking_details() { $gss_model=new Gss_model(); $table = 'gss_bookings'; $instal_table = 'gss_booking_installments'; $booking_id = service('uri')->getSegment(2); $site_result = $gss_model->user_site_booking_details($booking_id); $where = array('booking_id'=>'6','delete_status'=>'ACTIVE'); $instal_result = $gss_model->get_where_result($instal_table,$where); if($site_result) { echo json_encode(array('result'=>1,'booking_details'=>$site_result,'instalments'=>$instal_result)); } else { echo json_encode(array('result'=>0)); } } public function check_enquired_user() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $customer_name = ucfirst($this->request->getpost('customer_name')); $mobile1 = $this->request->getpost('mobile1'); $result = $gss_model->check_enquired_user($customer_name,$mobile1); if($result) { echo json_encode(array('result'=>1,'data'=>$result)); } else { echo json_encode(array('result'=>0)); } } // public function sites_status_list() // { // $gss_model=new Gss_model(); // $project_id = $this->request->getpost('project_id'); // $result = $gss_model->sites_status_list($project_id); // if($result) // { // echo json_encode(array('site_status_list'=>$result,'result'=>1)); // } // else // { // echo json_encode(array('result'=>0)); // } // } public function delete_booking() { $db = \Config\Database::connect(); $gss_model=new Gss_model(); $booking_table = 'gss_bookings'; $detail_table = 'gss_booking_details'; $booking_id = $this->request->getpost('booking_id'); $where = array('booking_id'=>$booking_id); $data = array('delete_status'=>'INACTIVE'); $result = $gss_model->update1($booking_table, $where, $data); $result1 = $gss_model->update1($detail_table, $where, $data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to Delete']); } } public function upload() { helper(['form', 'url']); $gss_model = new Gss_model(); $table = 'gss_enquiries'; $file = $this->request->getFile('file'); if ($file && $file->isValid()) { $ext = $file->getClientExtension(); if (in_array($ext, ['xlsx', 'xls'])) { $inputFileName = $file->getTempName(); try { $spreadsheet = IOFactory::load($inputFileName); $sheet = $spreadsheet->getActiveSheet(); $allDataInSheet = $sheet->toArray(null, true, true, true); $arrayCount = count($allDataInSheet); // total rows if ($arrayCount > 1) { for ($i = 2; $i <= $arrayCount; $i++) { $customer_name = trim($allDataInSheet[$i]["B"]); $email = trim($allDataInSheet[$i]["C"]); $mobile = trim($allDataInSheet[$i]["D"]); $mobile2 = trim($allDataInSheet[$i]["E"]); $address = trim($allDataInSheet[$i]["F"]); $web_portal_address = trim($allDataInSheet[$i]["G"]); $database_name = trim($allDataInSheet[$i]["H"]); $reference = trim($allDataInSheet[$i]["I"]); $crts = trim($allDataInSheet[$i]["J"]); $enquiry_status = trim($allDataInSheet[$i]["K"]); $status = 'ACTIVE'; $crt = date("Y-m-d", strtotime($crts)); if ($customer_name) { $data = [ 'customer_name' => $customer_name, 'email' => $email, 'mobile' => $mobile, 'mobile2' => $mobile2, 'address' => $address, 'web_portal_address' => $web_portal_address, 'database_name' => $database_name, 'reference' => $reference, 'status' => $enquiry_status, 'delete_status' => $status, 'created_at' => $crt, ]; $gss_model->insert1($table, $data); } } return $this->response->setJSON([ 'status' => 'success', 'message' => 'Data uploaded successfully!' ]); } else { return $this->response->setJSON([ 'status' => 'error', 'message' => 'No data found in the file.' ]); } } catch (\Exception $e) { return $this->response->setJSON([ 'status' => 'error', 'message' => 'Error loading file: ' . $e->getMessage() ]); } } else { return $this->response->setJSON([ 'status' => 'error', 'message' => 'Invalid file type. Please upload xlsx or xls.' ]); } } else { return $this->response->setJSON([ 'status' => 'error', 'message' => 'No file uploaded or file is invalid.' ]); } } public function get_sketch_mapping_tags() { $gss_model=new Gss_model(); $project_id = $this->request->getpost('project_id'); $condition=array('delete_status'=>'ACTIVE','project_id'=>$project_id); $table='gss_mapping'; $result = $gss_model->get_where_result($table,$condition); if($result) { return $this->response->setJSON(['result'=>1,'mapping_tags'=>$result]); } else { return $this->response->setJSON(['result'=>0]); } } public function add_project_details() { $gss_model=new Gss_model(); $table = 'gss_project_master'; $pro_name = $this->request->getpost('pro_name'); $pro_description = $this->request->getpost('pro_description'); $no_of_years = $this->request->getpost('no_of_years'); $per_sq_ft = $this->request->getpost('per_sq_ft'); $data = array('project_name'=>$pro_name,'description'=>$pro_description,'no_of_years'=>$no_of_years,'per_sq_ft'=>$per_sq_ft,'delete_status'=>'ACTIVE'); $condition=array('project_name'=>$pro_name,'description'=>$pro_description,'no_of_years'=>$no_of_years,'per_sq_ft'=>$per_sq_ft,'delete_status'=>'ACTIVE'); $get_det=$gss_model->get_where_row($table,$condition); if(empty($get_det)){ $result = $gss_model->insert1($table,$data); return $this->response->setJSON(['result'=>1,'message'=>'Added successfully']); } else { return $this->response->setJSON(['result'=>0,'message'=>'Data Already Exist']); } } public function get_project_sites() { $gss_model=new Gss_model(); $table = 'gss_new_sites'; $project_id=$_GET['project_id']; $result = $gss_model->get_where_result_site_ids($project_id); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function get_project_sites_edit() { $gss_model = new Gss_model(); // Validate input parameters $project_id = isset($_GET['project_id']) ? $_GET['project_id'] : null; $inv = isset($_GET['inv']) ? $_GET['inv'] : null; if (!$project_id) { return $this->response->setJSON(['error' => 'Missing project ID']); } if (!$inv) { return $this->response->setJSON(['error' => 'Missing invoice number (inv)']); } // Fetch result $result = $gss_model->get_where_result_site_ids_edit($project_id, $inv); // Return the result properly if (!empty($result)) { return $this->response->setJSON($result); // ✅ No extra wrapping in array } else { return $this->response->setJSON(['result' => 0, 'message' => 'No records found']); } } public function po_genereted_list_form() { $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $land_table = 'gss_project_master'; $data['project'] = $gss_model->get_where_result1111($land_table); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/po_genereted_list',$data); } else { redirect('/'); } } public function purchase_order_form() { $admin_id = session()->get('admin_id'); if($admin_id) { $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/purchase_order_form',$data); } else { redirect('/'); } } public function purchase_po_genereted_list_form() { $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $land_table = 'gss_project_master'; $data['project'] = $gss_model->get_where_result1111($land_table); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/purchase_po_genereted_list_form',$data); } else { redirect('/'); } } public function client_details_form() { $gss_model=new Gss_model(); $broker_table = 'gss_brokers'; $where_reference = array('delete_status'=>'ACTIVE','type'=>'Executives'); $order_by1 = 'associate_name'; $data['reference'] = $gss_model->get_where_result_alphabetical($broker_table,$where_reference,$order_by1); $land_table = 'gss_new_projects'; // $data['owners'] = $this->gss_model->get_where_result1111($land_table); $where_reference1 = array('delete_status'=>'ACTIVE'); $order_by2 = 'project_name'; $data['owners'] = $gss_model->get_where_result_alphabetical($land_table,$where_reference1,$order_by2); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/client_details_form',$data); } public function add_client_details() { $gss_model=new Gss_model(); $customer_name = $this->request->getpost('customer_name'); $relation = $this->request->getpost('relation'); $relative = $this->request->getpost('fa_hu_name'); $project_id = $this->request->getpost('project_id'); $mobile1 = $this->request->getpost('mobile11'); $mobile2 = $this->request->getpost('mobile12'); $email = $this->request->getpost('email'); $office_no = $this->request->getpost('office_no'); $address = $this->request->getpost('address'); $bday = $this->request->getpost('bday'); if($bday != "") { if (!empty($bday) && strtotime($bday) !== false) { $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); } else { $date = null; // Handle invalid date case } $bday = $date->format('Y-m-d'); } $doa = $this->request->getpost('doa'); if($doa != "") { if (!empty($doa) && strtotime($doa) !== false) { //$date = new DateTime( $doa); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); } else { $date = null; // Handle invalid date case } $doa = $date->format('Y-m-d'); } $executive = $this->request->getpost('reference'); $site_number = $this->request->getpost('site_number'); $site_dimension = $this->request->getpost('site_dimension'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $data = array('project_id'=>$project_id, 'customer_name'=>$customer_name, 'relation'=>$relation, 'father_or_husband'=>$relative, 'mobile1'=>$mobile1, 'mobile2'=>$mobile2, 'office_number'=>$office_no, 'email'=>$email, 'address'=>$address, 'dob'=>$bday, 'doa'=>$doa, 'reference'=>$executive, 'status'=>1, 'booking_status'=>"ENQUIRED", 'delete_status'=>'ACTIVE', 'created_at'=>$created_at); $booking_table = 'gss_bookings'; $detail_table = 'gss_booking_details'; //$where = array('delete_status'=>'ACTIVE','mobile1'=>$mobile1); $where_booked_site = array('delete_status'=>'ACTIVE','project_id'=>$project_id); $site_table = 'gss_new_sites'; $where_sites = array('project_id' => $project_id ,'delete_status' => 'ACTIVE'); $sites = $gss_model->get_where_result($site_table,$where_sites); $array2 = array(); foreach($sites as $value) { array_push($array2, $value->site_number); } $booked_site_table = "gss_booking_details"; $booked_sites = $gss_model->get_where_result($booked_site_table,$where_booked_site); $array1 = array(); foreach($booked_sites as $value) { array_push($array1, $value->site_number); } if(in_array($site_number,$array1)) { $booking_table = 'gss_bookings'; $order_by = 'booking_id'; $where1 = array('delete_status'=>'ACTIVE','project_id'=>$project_id,'site_number'=>$site_number); $check = $gss_model->get_where_orderby_row($detail_table,$where1,$order_by); $where2 = array('delete_status'=>'ACTIVE','booking_id'=>$check->booking_id,'project_id'=>$project_id); $status = $gss_model->get_where_orderby_row($booking_table,$where2,$order_by); if ($status && $status->booking_status == 'BOOKED') { return $this->response->setJSON(['result'=>2,'message'=>"Site already Booked.."]); } else if($status->booking_status == 'ENQUIRED') { return $this->response->setJSON(['result'=>2,'message'=>"Site already Enquired.."]); } else if($status->booking_status == 'CANCELLED' || $status->booking_status == 'REFUNDED') { $result = $gss_model->insert1($booking_table,$data); $table1='gss_booking_details'; $data1=array('project_id'=>$project_id, 'site_number'=>$site_number, 'dimension'=>$site_dimension, 'booking_id'=>$result); $result1 = $gss_model->insert1($table1,$data1); if($result1) { return $this->response->setJSON(['result'=>1,'message'=>"Client Details added successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); } } } else if(in_array($site_number,$array2)) { $result = $gss_model->insert1($booking_table,$data); $table1='gss_booking_details'; $data1=array('project_id'=>$project_id, 'site_number'=>$site_number, 'dimension'=>$site_dimension, 'booking_id'=>$result); $result1 = $gss_model->insert1($table1,$data1); if($result1) { return $this->response->setJSON(['result'=>1,'message'=>"Client Details added successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); } } else { $result = $gss_model->insert1($booking_table,$data); $table1='gss_booking_details'; $data1=array('project_id'=>$project_id, 'site_number'=>$site_number, 'dimension'=>$site_dimension, 'booking_id'=>$result); $result1 = $gss_model->insert1($table1,$data1); if($result1) { return $this->response->setJSON(['result'=>1,'message'=>"Client Details added successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); } } } public function client_booking_details() { $admin_id = session()->get('admin_id'); if($admin_id) { $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/client_list',$data); } else { redirect('/'); } } public function client_detail_list() { $gss_model=new Gss_model(); $table = 'gss_bookings'; $where = array('delete_status'=>'ACTIVE','status'=>1); $result = $gss_model->get_all_clients(); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function view_client_details() { $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $table = 'gss_bookings'; $booking_id = service('uri')->getSegment(2); $data['site_result'] = $gss_model->client_site_booking_details1($booking_id); $site_result = $gss_model->user_site_booking_details1($booking_id); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/view_client_details',$data); } else { redirect('/'); } } public function edit_client_details() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $web_table = 'gss_webportals'; $broker_table = 'gss_brokers'; $project_table = 'gss_new_projects'; $where_portal = array('delete_status'=>'ACTIVE'); $where_reference = array('delete_status'=>'ACTIVE','type'=>'Executives'); $where_logistics = array('delete_status'=>'ACTIVE','type'=>'Logistic'); $where_associate = array('delete_status'=>'ACTIVE','type'=>'Associate'); $where_subassociate = array('delete_status'=>'ACTIVE','type'=>'Sub Associate'); $where_project = array('delete_status'=>'ACTIVE'); $order_by_portal = 'webportal'; $order_by = 'associate_name'; $order_by_project = 'project_name'; $data['webportals'] = $gss_model->get_where_result_alphabetical($web_table,$where_portal,$order_by_portal); $data['reference'] = $gss_model->get_where_result_orderby_asc($broker_table,$where_reference,$order_by); $data['projects'] = $gss_model->get_where_result_orderby_asc($project_table,$where_project,$order_by_project); $booking_id = service('uri')->getSegment(2); $data['booking'] = $gss_model->client_booking_details($booking_id); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/edit_client_form',$data); } else { redirect('/'); } } //Update Client Details public function update_client_details() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $booking_table = 'gss_bookings'; $detail_table = 'gss_booking_details'; $booking_id = $this->request->getpost('booking_id'); $detail_id = $this->request->getpost('detail_id'); $customer_name = $this->request->getpost('customer_name'); $relation = $this->request->getpost('relation'); $fa_hu_name = $this->request->getpost('fa_hu_name'); $email = $this->request->getpost('email'); $alternative_email = $this->request->getpost('alternative_email'); $mobile1 = $this->request->getpost('mobile11'); $mobile2 = $this->request->getpost('mobile12'); $office_no = $this->request->getpost('office_no'); $bday = $this->request->getpost('bday'); if (!empty($bday) && strtotime($bday) !== false) { $date = new \DateTime($bday); // ✅ Add backslash to use global DateTime class $bday = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format } else { $bday = null; // Handle invalid or empty date } $doa = $this->request->getpost('doa'); if (!empty($doa) && strtotime($doa) !== false) { $date = new \DateTime($doa); // ✅ Use global DateTime class $doa = $date->format('Y-m-d'); // Convert to 'YYYY-MM-DD' format } else { $doa = null; // Handle invalid or empty date } $address = $this->request->getpost('address'); $reference = $this->request->getpost('reference'); $project_id = $this->request->getpost('project_id'); $site_number = $this->request->getpost('site_number'); $site_dimension = $this->request->getpost('site_dimension'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); //$mobile = json_encode(array($mobile1, $mobile2)); $booking_data = array( 'project_id' => $project_id, 'customer_name' => $customer_name, 'relation' => $relation, 'father_or_husband' => $fa_hu_name, 'email' => $email, 'alternative_email' => $alternative_email, 'mobile1' => $mobile1, 'mobile2' => $mobile2, 'dob' => $bday, 'doa' => $doa, 'address' => $address, 'reference' => $reference, 'status' => 1, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ); $detail_data = array( 'booking_id' => $booking_id, 'project_id' => $project_id, 'site_number' => $site_number, 'dimension' => $site_dimension, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ); // print_r($booking_data); $where_detail = ['booking_id' => $booking_id]; //print_r($where_detail); $where_booking = ['booking_id' => $booking_id]; $detail_result = $gss_model->update1($detail_table,$where_detail,$detail_data); // print_r($detail_result ); // die(); if ($db->affectedRows() > 0) { $detail = $gss_model->update1($booking_table,$where_booking,$booking_data); return $this->response->setJSON(['result' => 1,'message' => "Updated successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); } } public function check_project_status() { $gss_model=new Gss_model(); $project_id = $this->request->getpost('project_id'); $site_number = $this->request->getpost('site_number'); $check_site = $gss_model->project_details($site_number,$project_id); if($check_site) { $site_result = $gss_model->payment_site_booking_details1($site_number,$project_id); if(!empty($site_result)) { if($site_result->booking_status == 'BOOKED') { return $this->response->setJSON(['result'=>0,'dimension'=>$site_result->total_in_sqft,'message'=>'Site number '.$site_number.' has been already BOOKED']); } else if($site_result->booking_status == 'ENQUIRED') { return $this->response->setJSON(['result'=>0,'dimension'=>$site_result->total_in_sqft,'message'=>'Site number '.$site_number.' has been already ENQUIRED']); } } else { $check_site_result = $gss_model->payment_site_booking_details2($site_number,$project_id); if($check_site_result) { return $this->response->setJSON(['result'=>1,'dimension'=>$check_site_result->total_in_sqft]); } else { } } } else { } } public function check_project_sites_for_booked() { $db = \Config\Database::connect(); $project_id = trim($this->request->getPost('project_id')); $site_number = trim($this->request->getPost('site_number')); $builder = $db->table('gss_bookings A'); $query = $builder->select('A.*, C.*') ->join('gss_booking_details C', 'C.booking_id = A.booking_id') ->where('A.delete_status', 'ACTIVE') ->where('C.delete_status', 'ACTIVE') ->where('C.project_id', $project_id) ->where('C.site_number', $site_number) ->get(); $result = $query->getRow(); if ($result) { return $this->response->setJSON([ 'details' => $result, 'result' => ($result->booking_status == 'BOOKED') ? 1 : 0 ]); } else { return $this->response->setJSON(['result' => 0]); } } public function get_site_dimensions() { $db = \Config\Database::connect(); $project_id = trim($this->request->getPost('project_id')); $site_number = trim($this->request->getPost('site_number')); log_message('debug', "Checking dimensions for project_id: $project_id, site_number: $site_number"); $builder = $db->table('gss_new_sites'); $builder->select('total_in_sqft, status') ->where('delete_status', 'ACTIVE') ->where('project_id', $project_id) ->where('site_number', $site_number); // Debugging: Get SQL Query $sql = $builder->getCompiledSelect(); log_message('debug', "SQL Query: $sql"); $query = $builder->get(); $result = $query->getRow(); if ($result) { return $this->response->setJSON([ 'total_sqft' => $result->total_in_sqft, 'khata_status' => $result->status, 'result' => 1 ]); } else { log_message('debug', "No data found for the given project_id and site_number."); return $this->response->setJSON(['result' => 0, 'message' => "No Data Found"]); } } // public function check_project_type_status() // { // $gss_model=new Gss_model(); // $status = $this->request->getPost('value'); // if($status == "ALL") // { // $where = array('delete_status'=>'ACTIVE'); // } // else // { // $where = array('project_status'=>$status,'delete_status'=>'ACTIVE'); // } // $order_by = 'project_name'; // $table = 'gss_new_projects'; // $admin_id = session()->get('admin_id'); // $land_owner_id = session()->get('land_owner_id'); // $check_status = $gss_model->get_projects_landownerwise($admin_id,$land_owner_id,$status); // if($check_status) // { // return $this->response->setJSON(['result'=>1,'message'=>$check_status]); // } // else // { // return $this->response->setJSON(['result'=>0,'message'=>'No Data Found']); // } // } public function preview_booking_details() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $table = 'gss_bookings'; $broker_table = 'gss_brokers'; $instal_table = 'gss_booking_installments'; $booking_id = service('uri')->getSegment(2); $data['site_result'] = $gss_model->user_site_booking_details1($booking_id); $site_result = $gss_model->user_site_booking_details1($booking_id); $where = array('booking_id'=>$booking_id,'delete_status'=>'ACTIVE'); $data['instal_result'] = $gss_model->get_where_row($instal_table,$where); $where = array('booking_id'=>$booking_id); $get_project = $gss_model->get_where_row($table,$where); $project_id = $get_project->project_id; $where_project = array('project_id'=>$project_id); $project_table = 'gss_new_projects'; $get_project_details = $gss_model->get_where_row($project_table,$where_project); $data['project'] = $get_project_details; $land_owner = $get_project_details->land_owner_id; $land_owner_table = 'gss_land_owners'; $where_land_owner = array('owner_id'=>$land_owner); $get_land_owner = $gss_model->get_where_row($land_owner_table,$where_land_owner); $data['land_owner'] = $get_land_owner; $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); if($get_land_owner->name == 'GSS Project Consultants') { return view('admin/gss_receipt',$data); } else { return view('admin/gss_ack',$data); } //$this->load->view('admin/preview_booking_details',$data); } else { redirect('/'); } } public function send_mail_receipt() { $gss_model=new gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $booking_id = $this->request->getpost('booking_ids'); $receipt_type = $this->request->getpost('receipt_type'); $ack_no1 = $this->request->getpost('ack_no1'); $ack_no2 = $this->request->getpost('ack_no2'); if($ack_no2 == 0) { $ack_no1 = $this->request->getpost('ack_no1'); } else { $ack_no1 = $this->request->getpost('ack_no2'); } $booking_date1 = $this->request->getpost('booking_date1'); $booking_date2 = $this->request->getpost('booking_date2'); $booking_amount1 = $this->request->getpost('booking_amount1'); $booking_amount2 = $this->request->getpost('booking_amount2'); $booking_count1 = $this->request->getpost('booking_count'); $booking_count2 = $this->request->getpost('booking_count2'); if($booking_count2 == 0) { $booking_count1 = $this->request->getpost('booking_count'); } else { $booking_count1 = $this->request->getpost('booking_count2'); } $booking_payment_particulars1 = $this->request->getpost('booking_payment_particulars1'); $booking_payment_particulars2 = $this->request->getpost('booking_payment_particulars2'); $db = \Config\Database::connect(); $table ='gss_login'; $where = array('user_id'=>$admin_id); $user = $gss_model->get_where_row($table,$where); $logged_in_email = $user->email; $where_b_id = array('booking_id'=>$booking_id); $booking_table = 'gss_bookings'; $client = $gss_model->get_where_row($booking_table,$where_b_id); $booking_detail_table = 'gss_booking_details'; $client_site = $gss_model->get_where_row($booking_detail_table,$where_b_id); $client_email = $client->email; $project_table = 'gss_new_projects'; $project_id = $client->project_id; $where_project = array('project_id'=>$project_id); $project = $gss_model->get_where_row($project_table,$where_project); $land_owner = $project->land_owner_id; $address =$project->land_owner_address; $land_owner_table = 'gss_land_owners'; $where_land_owner = array('owner_id'=>$land_owner); $get_land_owner = $gss_model->get_where_row($land_owner_table,$where_land_owner); $land_owner_address = $get_land_owner->address; $client_name = $client->customer_name; $project_name = $project->project_name; $site_number = $client_site->site_number; $particulars = $ack_no1.', Payment Type towards '.$booking_count1; $subject = $project_name.', '.$site_number.' and '.$client_name.' - '.$particulars; $message = 'Dear '.$client_name.', Please find enclosed the Receipt Details of '.$booking_count1; $table = 'gss_email_details'; $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $today = $date->format('d-m-Y'); $data = array('user_email'=>$logged_in_email, 'client_email' => $client_email, 'client_name' => $client_name, 'project_name' => $project_name, 'site_number' => $site_number, 'particulars' => $particulars, 'subject' => $subject, 'created_at' => $created_at, 'message' => $message); $insert_result = $gss_model->insert1($table,$data); if($insert_result) { // include("assets/mpdf60/mpdf.php"); // $mpdf=new mPDF('A4'); // $mpdf->mirrorMargins = 1; $html = ''; $index = 1; if($receipt_type == 'GSS Project Consultants Pvt. Ltd.') { $email_content = ''; $email_content.= '<html>'; $email_content.= '<head>'; $email_content.= '</head>'; $email_content.= '<body style="width:900px;display:block;margin:auto !important; border-left:10px solid #E3000F;padding-left: 100px !important;padding-right: 100px !important;padding-top: 50px !important;padding-bottom: 50px !important;">'; $email_content.= '<div style="padding-bottom:10px;clear:both;">'; $email_content.= '<h2 style="text-align:center;padding-bottom:5px;">GSS Project Consultants Pvt. Ltd.</h2>'; $email_content.= '<img src="assets/images/header_line.png" style="display:block;margin:auto;padding-left:300px;">'; $email_content.= "<h2 style='font-size: 28px;line-height: 1.3;text-align:center;'>Project Name: $project_name <br>Address: $address"; $email_content.= '</div>'; $email_content.= '<div style="padding-bottom:15px;padding-top:15px;margin-bottom: 5px;position:relative;clear:both;">'; $email_content.= '<img src="assets/images/line.png" style="display:block;margin:auto;width: 100%;">'; $email_content.= '<div style="padding-top:10px;padding-bottom:10px;">'; $email_content.= '<table style="margin-bottom:0px !important;width:100%;">'; $email_content.= '<tr>'; /* $email_content.= "<td><p style='margin:0;font-size:18px;font-weight:bold;padding-top: 3px;'>Date: $today</p></td>";*/ $email_content.= '<td style="text-align:center;"><h3 style="margin-bottom:0px;margin-top:0px;text-align:center;color:#E40025;font-weight:bold;">RECEIPT</h3></td>'; //$email_content.= '<td style="text-align:right;"><p style="margin:0;font-size:18px;font-weight:bold;padding-top: 3px;">Receipt No: 1234</p></td>'; $email_content.= '</tr>'; $email_content.= '</table>'; $email_content.= '</div>'; $email_content.= '<img src="assets/images/line.png" style="display:block;margin:auto;width: 100%;">'; $email_content.= '</div>'; $email_content.= '<div style="padding-bottom:20px;clear:both;">'; $email_content.= '<div>'; $email_content.= '<table style="margin-bottom:0px !important;width:100%;">'; $email_content.= '<tr>'; $email_content.= "<td><p style='padding-left: 50px;margin:0;font-size:18px;font-weight:bold;padding-top: 3px;'>Client Name: $client_name</p></td>"; $email_content.= "<td><p style='padding-right:50px;margin:0;text-align:right;font-size:18px;font-weight:bold;padding-top: 3px;'>Site No: $site_number</p></td>"; $email_content.= '</tr>'; $email_content.= '</table>'; $email_content.= '</div>'; $email_content.= '</div>'; $email_content.= '<div style="clear:both;">'; $email_content.= '<table style="width:100%;border-collapse: collapse;border-color:red;" border="1">'; $email_content.= '<tr>'; $email_content.= '<td style="border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;">Payment Date</td>'; /* $email_content.= '<td style="border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;">Receipt No</td>';*/ $email_content.= '<td style="border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;">Amount</td>'; $email_content.= '<td style="border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;">Payment Type</td>'; $email_content.= '<td style="border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;">Particulars</td>'; $email_content.= '</tr>'; $email_content.= '<tr>'; $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_date1</td>"; /*$email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;width:20%;'>$ack_no1</td>";*/ $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_amount1</td>"; $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_count1</td>"; $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_payment_particulars1</td>"; $email_content.= '</tr>'; if($booking_date2 !== '') { $email_content.= '<tr>'; $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_date2</td>"; /* $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;width:20%;'>$ack_no2</td>";*/ $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_amount2</td>"; $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_count2</td>"; $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_payment_particulars2</td>"; $email_content.= '</tr>'; } $email_content.= '</table>'; $email_content.= '<p style="text-align:center;font-weight:bold;font-size:18px;line-height:1.8;padding-top:15px;margin-bottom:4px;">(The validity of this receipt is subject to realization of all <br>cheques/demand draft/account transfer)</p>'; $email_content.= '<p style="text-align:center;font-weight:bold;font-size:18px;line-height:1.8;margin-top:4px;">This is a computer generated receipt. Signature is not required.</p>'; $email_content.= '</div>'; $email_content.= '<div class="row row_five" style="clear:both;padding-top:50px;">'; $email_content.= '<p style="margin-bottom:0px;margin-top:0px;font-size:18px;font-weight:bold;padding-top: 3px;">For GSS Project Consultants</p>'; $email_content.= '<p style="padding-left:30px;padding-top:50px;margin-bottom:0px;margin-top:0px;font-size:18px;font-weight:bold;">Authorized Signatory</p>'; $email_content.= '</div>'; $email_content.= '</body>'; $email_content.= '</html>'; } else { $email_content = ''; $email_content.= '<html>'; $email_content.= '<head>'; $email_content.= '</head>'; $email_content.= '<body style="width:900px;display:block;margin:auto !important; border-left:10px solid #E3000F !important;padding-left: 100px !important;padding-right: 100px !important;padding-top: 50px !important;padding-bottom: 50px !important;">'; $email_content.= '<div style="padding-bottom:10px;clear:both;">'; $email_content.= '<h2 style="text-align:center;padding-bottom:5px;">Acknowledgement</h2>'; $email_content.= '<img src="assets/images/header_line.png" style="display:block;margin:auto;padding-left:45%;">'; $email_content.= "<h2 style='font-size: 28px;line-height: 1.3;text-align:center;border-top:10px solid #E3000F !important;'>Project Name: $project_name <br>Address: $land_owner_address"; $email_content.= '</div>'; $email_content.= '<div style="padding-bottom:15px;padding-top:15px;margin-bottom: 5px;position:relative;clear:both;">'; $email_content.= '<img src="assets/images/line.png" style="display:block;margin:auto;width: 100%;">'; $email_content.= '<div style="padding-top:10px;padding-bottom:10px;">'; $email_content.= '<table style="margin-bottom:0px !important;width:100%;">'; $email_content.= '<tr>'; /* $email_content.= "<td><p style='margin:0;font-size:18px;font-weight:bold;padding-top: 3px;'>Date: $today</p></td>";*/ $email_content.= "<td><p style='padding-left: 50px;margin:0;font-size:18px;font-weight:bold;padding-top: 3px;'>Client Name: $client_name</p></td>"; $email_content.= "<td><p style='padding-right:50px;margin:0;text-align:right;font-size:18px;font-weight:bold;padding-top: 3px;'>Site No: $site_number</p></td>"; //$email_content.= '<td style="text-align:right;"><p style="margin:0;font-size:18px;font-weight:bold;padding-top: 3px;">Ack No: 01</p></td>'; $email_content.= '</tr>'; $email_content.= '</table>'; $email_content.= '</div>'; $email_content.= '<img src="assets/images/line.png" style="display:block;margin:auto;width: 100%;">'; $email_content.= '</div>'; /* $email_content.= '<div style="padding-bottom:20px;clear:both;">'; $email_content.= '<div>'; $email_content.= '<table style="margin-bottom:0px !important;width:100%;">'; $email_content.= '<tr>'; $email_content.= "<td><p style='padding-left: 50px;margin:0;font-size:18px;font-weight:bold;padding-top: 3px;'>Client Name: $client_name</p></td>"; $email_content.= "<td><p style='padding-right:50px;margin:0;text-align:right;font-size:18px;font-weight:bold;padding-top: 3px;'>Site No: $site_number</p></td>"; $email_content.= '</tr>'; $email_content.= '</table>'; $email_content.= '</div>'; $email_content.= '</div>';*/ $email_content.= '<div style="clear:both;">'; $email_content.= '<table style="width:100%;border-collapse: collapse;border-color:red;" border="1">'; $email_content.= '<tr>'; $email_content.= '<td style="border-top: 3px solid red !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;">Payment Date</td>'; /* $email_content.= '<td style="border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;">Ack No</td>';*/ $email_content.= '<td style="border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;">Amount</td>'; $email_content.= '<td style="border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;">Payment Type</td>'; $email_content.= '<td style="border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;">Particulars</td>'; $email_content.= '</tr>'; $email_content.= '<tr>'; $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_date1</td>"; /* $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;width:20%;'>$ack_no1</td>";*/ $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_amount1</td>"; $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_count1</td>"; $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_payment_particulars1</td>"; $email_content.= '</tr>'; if($booking_date2 !== '') { $email_content.= '<tr>'; $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_date2</td>"; /*$email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$ack_no2</td>";*/ $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_amount2</td>"; $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_count2</td>"; $email_content.= "<td style='border: 3px solid #e40025 !important;padding:8px 5px;font-weight:bold;font-size:16px;text-align:center;'>$booking_payment_particulars2</td>"; $email_content.= '</tr>'; } $email_content.= '</table>'; $email_content.= '<p style="text-align:center;font-weight:bold;font-size:18px;line-height:1.8;padding-top:15px;margin-bottom:4px;">(The validity of this receipt is subject to realization of all <br>cheques/demand draft/account transfer)</p>'; $email_content.= '<p style="text-align:center;font-weight:bold;font-size:18px;line-height:1.8;margin-top:4px;">This is a computer generated receipt. Signature is not required.</p>'; $email_content.= '</div>'; $email_content.= '</body>'; $email_content.= '</html>'; } // $mpdf->SetDisplayMode('fullpage'); // $mpdf->watermark_font = 'DejaVuSansCondensed'; // $mpdf->showWatermarkText = true; // $mpdf->WriteHTML($email_content); require ROOTPATH . 'vendor/autoload.php'; // Ensure this is correct $mpdf = new Mpdf(); $mpdf->WriteHTML($email_content); $name = 'client_receipt' . $insert_result . '.pdf'; $data = ['email_receipt' => $name]; $where = ['id' => $insert_result]; $result = $gss_model->update1($table, $where, $data); $mpdf->Output(WRITEPATH . '../public/email_receipts/' . $name, 'F'); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result'=>1 ,'message'=>$insert_result]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Data could not be added"]); } } else { return $this->response->setJSON(['result'=>0,'message'=>"Data could not be added"]); } //$this->load->view('admin/send_email',$data); } else { redirect('/'); } } public function view_mail_content() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $id = service('request')->getUri()->getSegment(2); $table = 'gss_email_details'; $where = array('id'=>$id); $data['details'] = $gss_model->get_where_row($table,$where); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/send_email',$data); } else { redirect('/'); } } public function send_receipt_email() { $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $id = $this->request->getpost('id'); $to = $this->request->getpost('to'); $table = 'gss_email_details'; $where = array('id'=>$id); $details = $gss_model->get_where_row($table,$where); $data = array('client_email'=>$to); $update = $gss_model->update1($table,$where,$data); $user_email = $details->user_email; $client_email = $details->client_email; $subject = $details->subject; $login_table = 'gss_login'; $where_login = array('user_id'=>$admin_id); $get_sign = $gss_model->get_where_row($login_table,$where_login); $email = $get_sign->email; $mail_password =$get_sign->mail_password; $sign = $get_sign->signature; $base_url = base_url(); $message = $details->message; $message .= '<br>'; $message .= '<br>'; $message .= 'Thanks and regards,<br>'; $message .= '<br>'; $message .= "<img src='".$base_url."public/assets/images/gss_logo.jpg' style='width:20%'>"; $message .= '<br>'; $message .= $sign; // $body = $message; $file = $details->email_receipt; $email = \Config\Services::email(); // $config = array( // 'protocol' => 'smtp', // 'smtp_host' => 'ssl://smtp.googlemail.com', // 'smtp_port' => 465, // 'smtp_user' => 'gssorganised@gmail.com', // 'smtp_pass' => 'GSSKarthi@1236#', // 'mailtype' => 'html', // 'charset' => 'utf-8' // ); // $this->email->initialize($config); // $this->email->set_mailtype("html"); // $this->email->set_newline("\r\n"); // $this->email->from($user_email,'GSS'); // change it to yours // $this->email->to($client_email,'GSS');// change it to yours // $this->email->subject($subject); // $this->email->message($message); // $this->email->attach('./email_receipts/'.$file); require_once 'public/email/PHPMailerAutoload.php'; $phpMailer = new PHPMailer(true); //$phpMailer->isSMTP(); $phpMailer->Host = "ssl://smtp.googlemail.com"; $phpMailer->SMTPAuth = true; $phpMailer->Username = "gssorganised@gmail.com"; $phpMailer->Password = "GSSKarthi@1236#"; $phpMailer->SMTPSecure = "tls"; $phpMailer->Port = 587; $phpMailer->isHTML(true); $phpMailer->CharSet = "UTF-8"; $phpMailer->setFrom($user_email, "GSS"); $phpMailer->addAddress($client_email); //$phpMailer->addAddress('sowmyayp@gmail.com'); $phpMailer->Subject = $subject; $phpMailer->Body = $message; //$phpMailer->AddCC('sowmyashreelr@gmail'); $phpMailer->AddCC($email); $phpMailer->addAttachment('public/email_receipts/'.$file); if ($phpMailer->send()) { return $this->response->setJSON(['result'=>1,'message'=>'Your Email has successfully been sent.']); } else { return $this->response->setJSON(['result'=>0,'message'=>'Something Went Wrong!']); show_error($this->email->print_debugger()); } } else { redirect('/'); } } // // Documentation projects form // public function documentation_project_form() // { // $session = session(); // $admin_id = $session->get('admin_id'); // if (!$admin_id) { // return redirect()->to('/'); // } // // Fetch active projects using Query Builder // $builder = $this->db->table('gss_project_master') // ->select('*') // ->where('delete_status', 'ACTIVE') // ->get(); // // Get user type ID directly inside this function // $user_type_id = $session->get('user_type_id'); // // Get access details directly inside this function // $access = [ // 'can_edit' => true, // 'can_delete' => false // ]; // Modify this based on actual access logic // $data = [ // 'projects' => $builder->getResult(), // 'user_type_id' => $user_type_id, // 'access' => $access // ]; // return view('admin/doc_project_form', $data); // } // public function add_documentation_project() // { // $db = db_connect(); // $request = service('request'); // $project_name = $request->getPost('project_name'); // $project_owner_name = $request->getPost('project_owner_name'); // $uploadFile = function ($file, $path) { // if ($file && $file->isValid() && !$file->hasMoved()) { // $newName = time() . '_' . $file->getClientName(); // $file->move(WRITEPATH . '../public/' . $path, $newName); // return $newName; // } // return ''; // }; // $approved_plan_image = $uploadFile($request->getFile('approved_plan_image'), 'documentation_approved_uploads'); // $release_order_image = $uploadFile($request->getFile('release_order_image'), 'documentation_release_uploads'); // $conversion_order = $uploadFile($request->getFile('conversion_order'), 'documentation_conversion_uploads'); // $brochure = $uploadFile($request->getFile('brochure'), 'documentation_brochure_uploads'); // // Handling multiple file uploads for conversion_order_image // $conversion_images = []; // $conversion_files = $request->getFileMultiple('conversion_order_image'); // if ($conversion_files) { // foreach ($conversion_files as $file) { // if ($file->isValid() && !$file->hasMoved()) { // $filename = $uploadFile($file, 'documentation_other_uploads'); // $conversion_images[] = [ // 'image' => $filename, // 'name' => $request->getPost('conversion_doc_name') // ]; // } // } // } // $conversion_order_image = json_encode($conversion_images); // $created_at = date('Y-m-d H:i:s'); // $data = [ // 'project_name' => $project_name, // 'project_owner_name' => $project_owner_name, // 'approval_image' => $approved_plan_image, // 'other_image' => $conversion_order_image, // 'release_image' => $release_order_image, // 'conversion_order' => $conversion_order, // 'brochure' => $brochure, // 'delete_status' => 'ACTIVE', // 'created_at' => $created_at // ]; // $db->table('gss_doc_projects')->insert($data); // if ($db->affectedRows() > 0) { // return $this->response->setJSON(['result' => 1, 'message' => 'Project Added!']); // } else { // return $this->response->setJSON(['result' => 0, 'message' => 'Data could not be added']); // } // } // public function documentation_project_list() // { // $session = session(); // $admin_id = $session->get('admin_id'); // if ($admin_id) { // $db = db_connect(); // $data['projects'] = $db->table('gss_project_master') // ->where('delete_status', 'ACTIVE') // ->get() // ->getResult(); // $data['user_type_id'] = session()->get('user_type_id'); // $data['access'] = ['can_edit' => true, 'can_delete' => false]; // Adjust as needed // return view('admin/doc_project_list', $data); // } else { // return redirect()->to('/'); // } // } // public function documentation_site_form() // { // $admin_id = session()->get('admin_id'); // if($admin_id) // { // $gss_model=new Gss_model(); // $table = "gss_doc_projects"; // $where = array('delete_status'=>'ACTIVE'); // $data['projects'] = $gss_model->get_where_result($table,$where); // $data['user_type_id'] = $this->access_id(); // $data['access'] = $this->access_details(); // return view('admin/doc_site_form',$data); // } // else // { // redirect('/'); // } // } // public function documentation_site_list() // { // $admin_id = session()->get('admin_id'); // if($admin_id) // { // $gss_model=new Gss_model(); // $table = "gss_doc_projects"; // $where = array('delete_status'=>'ACTIVE'); // $data['projects'] = $gss_model->get_where_result($table,$where); // $data['user_type_id'] = $this->access_id(); // $data['access'] = $this->access_details(); // return view('admin/doc_site_list',$data); // } // else // { // redirect('/'); // } // } // public function owner_document_form() // { // $admin_id = session()->get('admin_id'); // if($admin_id) // { // $gss_model=new Gss_model(); // $table = "gss_doc_projects"; // $where = array('delete_status'=>'ACTIVE'); // $data['projects'] = $gss_model->get_where_result($table,$where); // $data['user_type_id'] = $this->access_id(); // $data['access'] = $this->access_details(); // return view('admin/doc_owner_form',$data); // } // else // { // redirect('/'); // } // } // public function owner_document_list() // { // $gss_model=new Gss_model(); // $admin_id = session()->get('admin_id'); // if($admin_id) // { // $data['user_type_id'] = $this->access_id(); // $data['access'] = $this->access_details(); // $table = "gss_doc_projects"; // $where = array('delete_status'=>'ACTIVE'); // $order_by = 'project_name'; // $data['projects'] = $gss_model->get_where_result_alphabetical($table,$where,$order_by); // return view('admin/doc_owner_document_list',$data); // } // else // { // redirect('/'); // } // } // public function client_document_form() // { // $gss_model=new Gss_model(); // $admin_id = session()->get('admin_id'); // if($admin_id) // { // $table = "gss_doc_projects"; // $where = array('delete_status'=>'ACTIVE'); // $order_by ="project_name"; // $data['projects'] = $gss_model->get_where_result_orderby_asc($table,$where,$order_by); // $data['user_type_id'] = $this->access_id(); // $data['access'] = $this->access_details(); // return view('admin/client_doc_form',$data); // } // else // { // redirect('/'); // } // } // public function client_document_list() // { // $admin_id = session()->get('admin_id'); // if($admin_id) // { // $gss_model=new Gss_model(); // $data['user_type_id'] = $this->access_id(); // $data['access'] = $this->access_details(); // $table = "gss_doc_projects"; // $where = array('delete_status'=>'ACTIVE'); // $order_by = 'project_name'; // $data['projects'] = $gss_model->get_where_result_alphabetical($table,$where,$order_by); // return view('admin/doc_client_document_list',$data); // } // else // { // redirect('/'); // } // } public function client_address_details() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $project_table = 'gss_new_projects'; $where_project = array('delete_status'=>'ACTIVE','project_status'=>'ONGOING'); $order_by = 'project_name'; $data['projects'] = $gss_model->get_where_result_orderby_asc($project_table,$where_project,$order_by); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/address_list',$data); } else { redirect('/'); } } //add public function get_address_list() { $gss_model=new Gss_model(); $p_poject = $_GET['p_poject']; $result = $gss_model->get_address_list($p_poject); //print_r($result);die(); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0,'message'=>'data not found')); } } public function new_sites() { $gss_model = new Gss_model(); // Adjust namespace if needed $project_id = $this->request->getGet('project_id'); // CI4 way of getting GET data if (!$project_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Missing project_id']); } $table = 'gss_new_sites'; $where = [ 'delete_status' => 'ACTIVE', 'project_id' => $project_id ]; $result = $gss_model->get_new_sites($table, $where); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No records found']); } } // Forms Maintenance Controller Codes Starts Here................................. public function maintenance_form() { $admin_id = session()->get('admin_id'); if($admin_id) { $GssNewProjectsModel = new GssNewProjectsModel(); $project_table = 'gss_new_projects'; $where_project = array('delete_status'=>'ACTIVE'); $order_by_project = 'project_name'; $data['projects'] = $GssNewProjectsModel->get_where_result_alphabetical($project_table,$where_project,$order_by_project); $booking_table ='gss_booking_details'; $where_booking = array('delete_status'=>'ACTIVE'); $data['bookings'] = $GssNewProjectsModel->get_where_result($booking_table,$where_booking); $table ='gss_project_master'; $where = array('delete_status'=>'ACTIVE'); $data['details'] = $GssNewProjectsModel->get_where_result($table,$where); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/maintenance_form',$data); } else { redirect('/'); } } public function add_maintenance_details() { $db = \Config\Database::connect(); $request = service('request'); $project_id = $request->getPost('project_id'); $site_number = $request->getPost('site_number'); $booking_id = $request->getPost('booking_id'); $site_dimension = $request->getPost('site_dimension'); $per_sqft = $request->getPost('per_sqft'); $maintainance_amount = str_replace(',', '', $request->getPost('maintainance_amount')); $no_of_years = $request->getPost('no_of_years'); $client_name = $request->getPost('client_name'); $maintenance_payment_type = $request->getPost('maintenance_payment_type'); $note = $request->getPost('note'); // Default Payment Variables $check_no1 = $check_date1 = $bank_name1 = $vtr_no1 = $online_date1 = $dd_no1 = $dd_date1 = $dd_bank1 = ""; $ref_no = $paytm_date = $upi_ref_no = $upi_date = $cash_payment_date = ""; // 🔹 Payment Mode Handling switch ($maintenance_payment_type) { case 'Cheque': $check_no1 = $request->getPost('check_no1'); $check_date1 = $this->formatDate($request->getPost('check_date1')); $bank_name1 = $request->getPost('bank_name1'); break; case 'Online Payment': $vtr_no1 = $request->getPost('vtr_no1'); $online_date1 = $this->formatDate($request->getPost('online_date1')); break; case 'DD': $dd_no1 = $request->getPost('dd_no1'); $dd_date1 = $this->formatDate($request->getPost('dd_date1')); $dd_bank1 = $request->getPost('dd_bank1'); break; case 'Paytm Payment': $ref_no = $request->getPost('ref_no'); $paytm_date = $this->formatDate($request->getPost('paytm_date')); break; case 'UPI Payment': $upi_ref_no = $request->getPost('upi_ref_no'); $upi_date = $this->formatDate($request->getPost('upi_date')); break; case 'Cash': $cash_payment_date = $this->formatDate($request->getPost('cash_payment_date')); break; } // 🔹 Determine Payment Status $payment_status = ($maintenance_payment_type) ? "RECEIVED" : "NOT RECEIVED"; $created_at = date('Y-m-d H:i:s', time()); // 🔹 Insert Data $data = [ 'booking_id' => $booking_id, 'project_id' => $project_id, 'site' => $site_number, 'dimension' => $site_dimension, 'per_sq_ft' => $per_sqft, 'main_amount' => $maintainance_amount, 'no_of_yrs' => $no_of_years, 'payment_mode' => $maintenance_payment_type, 'check_no' => $check_no1, 'check_date' => $check_date1, 'check_bank' => $bank_name1, 'vtr_no' => $vtr_no1, 'vtr_date' => $online_date1, 'dd_no' => $dd_no1, 'dd_date' => $dd_date1, 'dd_bank' => $dd_bank1, 'paytm_ref_no' => $ref_no, 'paytm_date' => $paytm_date, 'upi_ref_no' => $upi_ref_no, 'upi_date' => $upi_date, 'client_name' => $client_name, 'created_at' => $created_at, 'delete_status' => 'ACTIVE', 'maintenance_status' => $payment_status, 'note' => $note, 'cash_payment_date' => $cash_payment_date ]; // 🔹 Check if data already exists $existingSite = $db->table('gss_maintenance_details') ->select('site') ->where(['project_id' => $project_id, 'delete_status' => 'ACTIVE']) ->get() ->getResultArray(); $existingSitesArray = array_column($existingSite, 'site'); if (in_array($site_number, $existingSitesArray)) { return $this->response->setJSON(['result' => 2, 'message' => 'Data Already Exist']); } // 🔹 Insert Maintenance Details $inserted = $db->table('gss_maintenance_details')->insert($data); if ($inserted) { // 🔹 Update Booking Details $updateData = ['maintain_status' => 'RECEIVED']; $updated = $db->table('gss_booking_details') ->where(['project_id' => $project_id, 'site_number' => $site_number, 'delete_status' => 'ACTIVE']) ->update($updateData); if ($updated) { return $this->response->setJSON(['result' => 1, 'message' => 'Added successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong..']); } } return $this->response->setJSON(['result' => 0, 'message' => 'Failed to insert data']); } // 🔹 Utility Function to Format Date private function formatDate($date) { return ($date) ? date('Y-m-d', strtotime($date)) : null; } public function booked_site_maintenance_details() { $db = \Config\Database::connect(); $request = service('request'); $site_number = $request->getPost('site_number'); $project_id = $request->getPost('project_id'); if (!$site_number || !$project_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Site number and project ID are required']); } // 🔹 Check if site exists in the project $check_site = $db->table('gss_new_sites A') ->select('A.*, B.*') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->where([ 'A.delete_status' => 'ACTIVE', 'B.delete_status' => 'ACTIVE', 'A.site_number' => $site_number, 'A.project_id' => $project_id ]) ->get() ->getRow(); if (!$check_site) { return $this->response->setJSON(['result' => 2, 'message' => "Site number $site_number not found"]); } // 🔹 Check if site is booked for maintenance $get_site = $db->table('gss_bookings A') ->select('C.no_of_years as project_years, D.total_in_sqft as dimension, A.booking_id, C.maintenance_per_sqft as tsv_per_sft_rs, D.site_number, B.dimension as dimn, C.project_id, C.project_name, B.booking_id as b_booking_id, A.customer_name') ->join('gss_booking_details B', 'B.booking_id = A.booking_id') ->join('gss_new_projects C', 'C.project_id = B.project_id') ->join('gss_new_sites D', 'D.project_id = B.project_id AND D.site_number = B.site_number') ->where([ 'B.site_number' => $site_number, 'B.project_id' => $project_id, 'A.booking_status' => 'BOOKED', 'A.delete_status' => 'ACTIVE', 'B.delete_status' => 'ACTIVE', 'C.delete_status' => 'ACTIVE', 'D.delete_status' => 'ACTIVE' ]) ->orderBy('A.booking_id', 'DESC') ->get() ->getRow(); if (!$get_site) { return $this->response->setJSON(['result' => 0, 'message' => "Site number $site_number not booked"]); } // 🔹 Get booking details $details = $db->table('gss_bookings') ->select('*') ->where('booking_id', $get_site->booking_id) ->get() ->getRow(); return $this->response->setJSON([ 'result' => 1, 'details' => $details, 'booking_details' => $get_site ]); } public function maintenance_list() { $admin_id = session()->get('admin_id'); if($admin_id) { $GssNewProjectsModel= new GssNewProjectsModel(); $owner_table = 'gss_new_projects'; $where = array('delete_status'=>'ACTIVE'); $data['projects'] = $GssNewProjectsModel->get_where_result($owner_table,$where); $booking_table ='gss_booking_details'; $where_booking = array('delete_status'=>'ACTIVE'); $data['bookings'] = $GssNewProjectsModel->get_where_result($booking_table,$where_booking); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/maintenance_list',$data); } else { redirect('/'); } } public function get_maintainance_list() { $db = \Config\Database::connect(); $builder = $this->db->table('gss_maintenance_details A') ->select('A.project_id as a_project_id, A.*, B.project_name') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->orderBy('A.id', 'DESC'); $result = $builder->get()->getResult(); $array = []; foreach ($result as $val) { // Function inside the loop $formatIndianCurrency = function ($num) { $explrestunits = ""; if (strlen($num) > 3) { $lastthree = substr($num, strlen($num) - 3, strlen($num)); $restunits = substr($num, 0, strlen($num) - 3); $restunits = (strlen($restunits) % 2 == 1) ? "0" . $restunits : $restunits; $expunit = str_split($restunits, 2); foreach ($expunit as $i => $unit) { $explrestunits .= ($i == 0) ? (int) $unit . "," : $unit . ","; } return $explrestunits . $lastthree; } return $num; }; $data = [ 'id' => $val->id, 'project_name' => $val->project_name, 'site' => $val->site, 'dimension' => $val->dimension, 'per_sq_ft' => $val->per_sq_ft, 'client_name' => $val->client_name, 'main_amount' => $formatIndianCurrency($val->main_amount), // Apply formatting 'no_of_yrs' => $val->no_of_yrs ]; array_push($array, $data); } if ($array) { return $this->response->setJSON($array); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Data not found']); } } public function edit_maintenance() { $db = \Config\Database::connect(); $request = service('request'); $id = $request->getPost('id'); if (!$id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid ID']); } // 🔹 Query to get maintenance details $builder = $db->table('gss_maintenance_details A') ->select('A.project_id as a_project_id, A.*, B.project_name') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->where('A.id', $id) ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->get(); $result = $builder->getRow(); if (!$result) { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } // 🔹 Format the response data (date formatting inside controller) $data = [ 'project_name' => $result->project_name, 'project_id' => $result->project_id, 'id' => $result->id, 'site' => $result->site, 'dimension' => $result->dimension, 'per_sq_ft' => $result->per_sq_ft, 'note' => $result->note, 'cash_payment_date' => !empty($result->cash_payment_date) ? date("d-m-Y", strtotime($result->cash_payment_date)) : '', 'main_amount' => $result->main_amount, 'no_of_yrs' => $result->no_of_yrs, 'client_name' => $result->client_name, 'payment_mode' => $result->payment_mode, 'check_no' => $result->check_no, 'check_bank' => $result->check_bank, 'check_date' => !empty($result->check_date) ? date("d-m-Y", strtotime($result->check_date)) : '', 'vtr_no' => $result->vtr_no, 'vtr_date' => !empty($result->vtr_date) ? date("d-m-Y", strtotime($result->vtr_date)) : '', 'paytm_ref_no' => $result->paytm_ref_no, 'paytm_date' => !empty($result->paytm_date) ? date("d-m-Y", strtotime($result->paytm_date)) : '', 'dd_no' => $result->dd_no, 'dd_bank' => $result->dd_bank, 'dd_date' => !empty($result->dd_date) ? date("d-m-Y", strtotime($result->dd_date)) : '', 'upi_ref_no' => $result->upi_ref_no, 'upi_date' => !empty($result->upi_date) ? date("d-m-Y", strtotime($result->upi_date)) : '', ]; return $this->response->setJSON(['details' => $data, 'result' => 1]); } public function delete_maintenance() { $db = \Config\Database::connect(); $request = service('request'); $id = $request->getPost('id'); if (!$id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid ID']); } $table = 'gss_maintenance_details'; $maintain_table = 'gss_booking_details'; // 🔹 Soft delete by updating `delete_status` $deleteData = ['delete_status' => 'INACTIVE', 'main_amount' => '']; $builder = $db->table($table)->where('id', $id); $deleteResult = $builder->update($deleteData); if (!$deleteResult) { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to delete. Try again']); } // 🔹 Fetch project details after deletion $result = $db->table($table)->where('id', $id)->get()->getRow(); if (!$result) { return $this->response->setJSON(['result' => 0, 'message' => 'No matching record found']); } // 🔹 Update `gss_booking_details` maintain status $updateData = ['maintain_status' => 'NOT RECEIVED']; $updateCondition = [ 'project_id' => $result->project_id, 'site_number' => $result->site, 'delete_status' => 'ACTIVE' ]; $updateResult = $db->table($maintain_table)->where($updateCondition)->update($updateData); if ($updateResult) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to update booking details']); } } public function update_maintenance() { $db = \Config\Database::connect(); $request = service('request'); $id = $request->getPost('id'); if (!$id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid ID']); } // 🔹 Get request values $data = [ 'project_id' => $request->getPost('project_id'), 'site' => $request->getPost('site'), 'dimension' => $request->getPost('dimension'), 'per_sq_ft' => $request->getPost('per_sq_ft'), 'main_amount' => str_replace(',', '', $request->getPost('main_amount')), 'no_of_yrs' => $request->getPost('no_of_yrs'), 'payment_mode' => $request->getPost('maintenance_payment_type'), 'client_name' => $request->getPost('client_name'), 'note' => $request->getPost('note'), 'delete_status' => 'ACTIVE', 'updated_at' => date('Y-m-d H:i:s', time()) // Current timestamp ]; // 🔹 Inline date formatting function function formatDate($date) { return (!empty($date)) ? date("Y-m-d", strtotime($date)) : NULL; } // 🔹 Handle different payment modes & dates switch ($data['payment_mode']) { case 'Cheque': $data['check_no'] = $request->getPost('check_no1'); $data['check_date'] = formatDate($request->getPost('check_date1')); $data['check_bank'] = $request->getPost('bank_name1'); break; case 'Online Payment': $data['vtr_no'] = $request->getPost('vtr_no1'); $data['vtr_date'] = formatDate($request->getPost('online_date1')); break; case 'DD': $data['dd_no'] = $request->getPost('dd_no1'); $data['dd_date'] = formatDate($request->getPost('dd_date1')); $data['dd_bank'] = $request->getPost('dd_bank1'); break; case 'Paytm Payment': $data['paytm_ref_no'] = $request->getPost('ref_no'); $data['paytm_date'] = formatDate($request->getPost('paytm_date')); break; case 'UPI Payment': $data['upi_ref_no'] = $request->getPost('upi_ref_no'); $data['upi_date'] = formatDate($request->getPost('upi_date')); break; case 'Cash': $data['cash_payment_date'] = formatDate($request->getPost('cash_payment_date')); break; } // 🔹 Update database $builder = $db->table('gss_maintenance_details')->where('id', $id); $result = $builder->update($data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to update. Try again']); } } public function preview_maintenance_details($maintain_id = null) { $admin_id = session()->get('admin_id'); if (!$admin_id) { return redirect('/'); } $db = \Config\Database::connect(); $uri = service('uri'); $maintain_id = $this->request->getUri()->getSegment(2); if (!$maintain_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid maintenance ID']); } // 🔹 Get Maintenance Details (Inline Query) $query = $db->table('gss_maintenance_details A') ->select('A.*, B.customer_name') ->join('gss_bookings B', 'B.booking_id = A.booking_id') ->where('A.id', $maintain_id) ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->get(); $maintainance_data = $query->getRow(); if (!$maintainance_data) { return $this->response->setJSON(['result' => 0, 'message' => 'No maintenance details found']); } $data['maintain_data'] = $maintainance_data; // 🔹 Get Project Details (Inline Query) $project_query = $db->table('gss_maintenance_details') ->select('*') ->where('id', $maintain_id) ->get(); $get_project = $project_query->getRow(); if (!$get_project) { return $this->response->setJSON(['result' => 0, 'message' => 'Project details not found']); } $project_id = $get_project->project_id; $project_details_query = $db->table('gss_new_projects') ->select('*') ->where('project_id', $project_id) ->get(); $get_project_details = $project_details_query->getRow(); $data['project'] = $get_project_details; if (!$get_project_details) { return $this->response->setJSON(['result' => 0, 'message' => 'Project details retrieval failed']); } // 🔹 Get Land Owner Details (Inline Query) $land_owner = $get_project_details->land_owner_id; $land_owner_query = $db->table('gss_land_owners') ->select('*') ->where('owner_id', $land_owner) ->get(); $get_land_owner = $land_owner_query->getRow(); $data['land_owner'] = $get_land_owner; if (!$get_land_owner) { return $this->response->setJSON(['result' => 0, 'message' => 'Land owner details not found']); } // 🔹 Get User Access Details $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); // 🔹 Load View Based on Land Owner if ($get_land_owner->name == 'GSS Project Consultants') { return view('admin/maintainance_receipt', $data); } else { return view('admin/maintenance_acknowledgement', $data); } } public function send_maintenance_mail_receipt() { $db = \Config\Database::connect(); $session = session(); $admin_id = $session->get('admin_id'); if ($admin_id) { $request = service('request'); $maintain_id = $request->getPost('maintain_ids'); $receipt_type = $request->getPost('receipt_type'); $ack_no1 = $request->getPost('ack_no1'); $maintain_date1 = $request->getPost('maintain_date1'); $maintenance_amount = $request->getPost('maintenance_amount'); $maintenance_count = $request->getPost('maintenance_count'); $maintenance_payment_particulars1 = $request->getPost('maintenance_payment_particulars1'); // Get admin email $user = $this->db->table('gss_login')->getWhere(['user_id' => $admin_id])->getRow(); $logged_in_email = $user->email ?? ''; // Get maintenance details $client = $this->db->table('gss_maintenance_details A') ->select('A.*, B.customer_name, B.email') ->join('gss_bookings B', 'B.booking_id = A.booking_id') ->getWhere(['A.id' => $maintain_id]) ->getRow(); if (!$client) { return $this->response->setJSON(['result' => 0, 'message' => "Maintenance details not found"]); } $booking_id = $client->booking_id; $client_email = $client->email; $client_name = $client->customer_name; // Get project details $project = $this->db->table('gss_new_projects')->getWhere(['project_id' => $client->project_id])->getRow(); $project_name = $project->project_name; $address = $project->land_owner_address; // Get landowner details $land_owner = $this->db->table('gss_land_owners')->getWhere(['owner_id' => $project->land_owner_id])->getRow(); $land_owner_address = $land_owner->address; $site_number = $client->site; $particulars = "$ack_no1, Payment Type towards $maintenance_count"; $subject = "$project_name, $site_number and $client_name - $particulars"; $message = "Dear $client_name, Please find enclosed the Receipt Details of $maintenance_count"; // Save email details $created_at = date('Y-m-d H:i:s'); $today = date('d-m-Y'); $email_data = [ 'user_email' => $logged_in_email, 'client_email' => $client_email, 'client_name' => $client_name, 'project_name' => $project_name, 'site_number' => $site_number, 'particulars' => $particulars, 'subject' => $subject, 'created_at' => $created_at, 'message' => $message ]; $this->db->table('gss_email_details')->insert($email_data); $insert_result = $this->db->insertID(); if ($insert_result) { // Generate Email Content (HTML) $email_content = "<html><head></head><body style='width:900px;margin:auto;padding:50px;border-left:10px solid #E3000F;'>"; $email_content .= "<h2 style='text-align:center;'>Maintenance Receipt</h2>"; $email_content .= "<h3 style='text-align:center;'>Project: $project_name | Address: $address</h3>"; $email_content .= "<h3>Client: $client_name | Site No: $site_number</h3>"; $email_content .= "<table border='1' width='100%' style='border-collapse: collapse;'> <tr> <th>Payment Date</th> <th>Maintenance Amount</th> <th>Payment Type</th> <th>Particulars</th> </tr> <tr> <td style='text-align:center;'>$maintain_date1</td> <td style='text-align:center;'>$maintenance_amount</td> <td style='text-align:center;'>$maintenance_count</td> <td style='text-align:center;'>$maintenance_payment_particulars1</td> </tr> </table>"; $email_content .= "<p style='text-align:center;font-size:16px;margin-top:20px;'>This is a computer-generated receipt. No signature required.</p>"; $email_content .= "</body></html>"; // Generate PDF $mpdf = new Mpdf(); $mpdf->WriteHTML($email_content); $file_name = 'client_receipt' . $insert_result . '.pdf'; $mpdf->Output(FCPATH . "email_receipts/" . $file_name, 'F'); // Update email details with PDF path $this->db->table('gss_email_details')->update(['email_receipt' => $file_name], ['id' => $insert_result]); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => $insert_result]); } } return $this->response->setJSON(['result' => 0, 'message' => "Data could not be added"]); } return redirect()->to('/'); } public function booked_site_payment_details() { $db = \Config\Database::connect(); $request = service('request'); $site_number = $request->getPost('site_number'); $project_id = $request->getPost('project_id'); // 🔹 Check if Site Exists $check_site = $db->table('gss_new_sites A') ->select('A.*, B.*') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->where(['A.delete_status' => 'ACTIVE', 'B.delete_status' => 'ACTIVE']) ->where('A.site_number', $site_number) ->where('A.project_id', $project_id) ->get() ->getRow(); if ($check_site) { // 🔹 Check if Site has Booking Details $get_site = $db->table('gss_bookings A') ->select('A.booking_id as booking_id1, A.*, B.booking_id as booking_id2, B.*, B.detail_id, C.project_id, C.project_name, C.nick_name, D.total_in_sqft, E.*') ->join('gss_booking_details B', 'B.booking_id = A.booking_id') ->join('gss_new_projects C', 'C.project_id = A.project_id') ->join('gss_new_sites D', 'D.project_id = C.project_id') ->join('gss_plot_payments E', 'E.booking_id = A.booking_id', 'left') ->where([ 'A.delete_status' => 'ACTIVE', 'B.delete_status' => 'ACTIVE', 'C.delete_status' => 'ACTIVE', 'D.delete_status' => 'ACTIVE' ]) ->where('A.project_id', $project_id) ->where('B.site_number', $site_number) ->where('A.booking_status !=', 'CANCELLED') ->orderBy('A.booking_id', 'DESC') ->get() ->getRow(); if ($get_site) { if ($get_site->booking_status == 'CANCELLED') { return $this->response->setJSON(['result' => 3, 'message' => 'Site number ' . $site_number . ' has been cancelled']); } else { // 🔹 Get Payment Details $where_agr_booking = ['booking_id' => $get_site->booking_id1, 'delete_status' => 'ACTIVE', 'agreement_delete_status' => 'ACTIVE']; $agree_result = $db->table('gss_plot_payments')->where($where_agr_booking)->get()->getRow(); $where_ins_booking = ['booking_id' => $get_site->booking_id1, 'delete_status' => 'ACTIVE', 'install_delete_status' => 'ACTIVE']; $instal_result = $db->table('gss_plot_payments')->where($where_ins_booking)->get()->getResult(); // 🔹 Registration Amount Details $get_reg_amt = $db->table('gss_registration_amount_details') ->where(['booking_id' => $get_site->booking_id1, 'delete_status' => 'ACTIVE']) ->get() ->getResult(); // 🔹 Due Amount from Cancellations $get_due_amount = $db->table('gss_cancellations') ->where(['booking_id' => $get_site->booking_id1, 'delete_status' => 'ACTIVE']) ->get() ->getRow(); // 🔹 Agreement Payment Details $agr_amount = $db->table('gss_plot_payments') ->where(['booking_id' => $get_site->booking_id1, 'delete_status' => 'ACTIVE', 'agreement_delete_status' => 'ACTIVE']) ->get() ->getResult(); // 🔹 Refunds from Cancellations $refunds = $db->table('gss_cancellation_refunds') ->where(['booking_id' => $get_site->booking_id1, 'delete_status' => 'ACTIVE']) ->get() ->getResult(); // 🔹 Booking Details $details = $db->table('gss_bookings') ->where(['booking_id' => $get_site->booking_id1]) ->get() ->getRow(); return $this->response->setJSON([ 'result' => 1, 'details' => $details, 'booking_details' => $get_site, 'installments' => $instal_result, 'agree' => $agree_result, 'reg_amount' => $get_reg_amt, 'due_amount' => $get_due_amount, 'payment_agr_amount' => $agr_amount, 'refunds' => $refunds ]); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Site number ' . $site_number . ' not booked']); } } else { return $this->response->setJSON(['result' => 2, 'message' => 'Site number ' . $site_number . ' not found']); } } public function get_maintenance_sites() { $db = \Config\Database::connect(); $request = service('request'); $project_id = $request->getPost('project_id'); if (!$project_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Project ID is required']); } // Query to get booked sites $query = $db->table('gss_bookings A') ->select('A.booking_id as a_booking_id, A.project_id as a_project_id, B.booking_amount1, B.booking_amount2, B.tsv, B.site_number') ->join('gss_booking_details B', 'B.booking_id = A.booking_id') ->whereNotIn('A.booking_status', ['CANCELLED', 'REFUNDED', 'ENQUIRED', 'REFUND_PENDING']) ->where('A.delete_status', 'ACTIVE') ->where('B.project_id', $project_id) ->orderBy('ABS(B.site_number)', 'ASC') ->get() ->getResult(); $array = []; foreach ($query as $val) { $booking_amount = (int) $val->booking_amount1 + (int) $val->booking_amount2; $tsv = (int) $val->tsv; $booking_id = (int) $val->a_booking_id; // Get Plot Payments $payments = $db->table('gss_plot_payments A') ->select('A.agreement_amount, A.installment_amount1, A.registration_amount') ->where([ 'A.booking_id' => $booking_id, 'A.agreement_delete_status' => 'ACTIVE', 'A.install_delete_status' => 'ACTIVE', 'A.registration_delete_status' => 'ACTIVE', 'A.delete_status' => 'ACTIVE' ]) ->get() ->getResult(); $tot_agree = 0; $tot_inst = 0; $tot_reg = 0; foreach ($payments as $pay) { $tot_agree = (int) $pay->agreement_amount; $tot_inst += (int) $pay->installment_amount1; $tot_reg = (int) $pay->registration_amount; break; // Only need the first entry } // Get Additional Registration Amounts $reg_payments = $db->table('gss_registration_amount_details A') ->select('A.reg_amount') ->where(['A.booking_id' => $booking_id, 'A.delete_status' => 'ACTIVE']) ->get() ->getResult(); $tot_reg1 = 0; foreach ($reg_payments as $reg) { $tot_reg1 += (int) $reg->reg_amount; } $total_registration = $tot_reg + $tot_reg1; $cal_tot = $booking_amount + $tot_agree + $tot_inst + $total_registration; if ($tsv == $cal_tot) { array_push($array, $val->site_number); } } if (!empty($array)) { return $this->response->setJSON(['result' => 1, 'sites' => $array]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No sites found']); } } // public function project_details() // { // $gss_model=new Gss_model(); // $admin_id = session()->get('admin_id'); // if($admin_id) // { // $project_table = 'gss_new_projects'; // $sites_table = 'gss_new_sites'; // $image_table = 'gss_nine_and_eleven_images'; // $conversin_orders = 'gss_project_conversion_orders'; // //$project_id = $this->uri->segment(2); // $project_id = $this->request->getUri()->getSegment(2); // ✅ CodeIgniter 4 Correct Method // $where = array('delete_status'=>'ACTIVE','project_id'=>$project_id); // $data['project_id'] = $project_id; // $table = 'gss_new_projects'; // $where = array('project_id'=>$project_id); // $get_land_owner_id = $gss_model->get_where_row($table, $where); // $land_owner_id = $get_land_owner_id->land_owner_id; // $tables = 'gss_land_owners'; // $wheres = array('owner_id'=>$land_owner_id); // $data['land_owner'] = $gss_model->get_where_row($tables, $wheres); // $condition=array('delete_status'=>'ACTIVE'); // $data['project'] = $gss_model->get_where_result($project_table,$condition); // $data['mappings'] = $gss_model->get_where_result_mapping_sketch(); // $table1 = 'gss_mapping_sketch'; // $where1 = array('project_id'=>$project_id ); // $data['sketch'] = $gss_model->get_where_row($table1,$where1); // $where_data = array('project_id'=>$project_id,'delete_status'=>'ACTIVE'); // $table_site='gss_new_sites'; // $data['site']=$gss_model->get_where_result($table_site,$where_data); // $table_mapping='gss_mapping'; // $data['site_id']=$gss_model->get_where_result($table_mapping,$where_data); // ////////////// // $data['project'] = $gss_model->get_where_row($project_table,$where); // $data['count'] = $gss_model->get_where_result($sites_table,$where); // $data['orders'] = $gss_model->get_where_result($conversin_orders,$where); // $where = array('delete_status'=>'ACTIVE','project_id'=>$project_id); // $data['release_orders'] = $gss_model->get_where_result($project_table,$where); // $data['user_type_id'] = $this->access_id(); // $data['access'] = $this->access_details(); // return view('admin/project_details',$data); // } // else // { // redirect('/'); // } // } public function close_new_project() { $gss_model=new Gss_model(); $table = 'gss_new_projects'; $project_id = $this->request->getpost('project_id'); $where = array('project_id'=>$project_id); $check_status = $gss_model->get_where_row($table, $where); if($check_status->project_status == 'ONGOING') { $data = array('project_status'=>'COMPLETED'); } else { $data = array('project_status'=>'ONGOING'); } $result = $gss_model->update1($table, $where, $data); // ✅ Correct order if($result > 0) { return $this->response->setJSON(['result'=>1,'message'=>'Changed successfully']); } else { return $this->response->setJSON(['result'=>0]); } } public function sites_status_list() { $gss_model=new Gss_model(); $project_id = $this->request->getpost('project_id'); $result = $gss_model->sites_status_list($project_id); if($result) { return $this->response->setJSON(['site_status_list'=>$result,'result'=>1]); } else { return $this->response->setJSON(['result'=>0]); } } public function update_mobile_project_status() { $project_id = $this->request->getPost('project_id'); $status = $this->request->getPost('status'); if($status == 'checked') { $status = 'SELECTED'; } else { $status = 'NOT_SELECTED'; } $update_data = array('mobile_status' => $status); $where_project = array('project_id' => $project_id); $project_table = 'gss_new_projects'; $update_result = $this->gss_model->update($where_project,$project_table,$update_data); if ($db->affectedRows() > 0) { echo json_encode(array('result'=> 1,'message' => "Updated Successfully")); } else { echo json_encode(array('result'=> 0,'message' => "Something went wrong.. try again")); } } public function commission_details() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $admin_id = session()->get('admin_id'); if($admin_id) { $management_table = 'gss_management'; $booking_id = service('uri')->getSegment(2); $where = array('booking_id'=>$booking_id); $data['aggreement'] = $gss_model->commission_dates_and_amounts($booking_id); $data['registration'] = $gss_model->commission_dates_and_amounts1($booking_id); $data['commission'] = $gss_model->commission($booking_id); //$data['subcommission'] = $this->gss_model->subcommission($booking_id); $data['user'] = $gss_model->single_user_account_management_list($booking_id); $data['subuser'] = $gss_model->subsingle_user_account_management_list($booking_id); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/commission_details',$data); } else { redirect('/'); } } public function get_site_project_details() { $gss_model=new Gss_model(); $site_id = $this->request->getpost('site_id'); $result = $gss_model->get_site_project_details($site_id); if($result) { return $this->response->setJSON(['site_details'=>$result,'result'=>1]); } else { return $this->response->setJSON(['result'=>0]); } } // public function get_site_project_details() // { // $gss_model=new Gss_model(); // $site_id = $this->request->getpost('site_id'); // $result = $gss_model->get_site_project_details($site_id); // if($result) // { // return $this->response->setJSON(['site_details'=>$result,'result'=>1]); // } // else // { // return $this->response->setJSON(['result'=>0]); // } // } public function delete_new_site() { $db = \Config\Database::connect(); $gss_model=new Gss_model(); $table = 'gss_new_sites'; $site_id = $this->request->getpost('site_id'); $where = array('site_id'=>$site_id); $data = array('delete_status'=>'INACTIVE'); $result = $gss_model->update1($table,$where,$data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result'=>1,'message'=>'Deleted successfully']); } else { return $this->response->setJSON(['result'=>0]); } } public function loan_form() { $admin_id = session()->get('admin_id'); $gss_model=new Gss_model(); if($admin_id) { $table = 'gss_login'; $booking_table = 'gss_bookings'; $where = ['user_type_id' => '6']; $data['booking_id'] = $this->request->getUri()->getSegment(2);; $booking_id = $this->request->getUri()->getSegment(2);; $where_booking = ['booking_id' => $booking_id]; $data['source_type'] = $gss_model->get_where_row($booking_table,$where_booking); $data['loan_admins'] = $gss_model->get_where_result($table,$where); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/loan_form',$data); } else { redirect('/'); } } public function add_loan_details() { $request = service('request'); $booking_id = $request->getPost('booking_id'); $sale_agreement_amount = str_replace(',', '', $request->getPost('sale_agreement_amount')); $loan_amount_applied = str_replace(',', '', $request->getPost('loan_amount_applied')); $financial_institution = $request->getPost('financial_institution'); $processing_fees = str_replace(',', '', $request->getPost('processing_fees')); $applied_on = $request->getPost('applied_on'); $source_type = $request->getPost('source_type'); $source_bank_name = $request->getPost('source_bank_name'); // Convert dates to Y-m-d format if not empty $applied_on = !empty($applied_on) ? date('Y-m-d', strtotime($applied_on)) : null; $sanctioned_date = !empty($request->getPost('sanctioned_date')) ? date('Y-m-d', strtotime($request->getPost('sanctioned_date'))) : null; $disbursed_date = !empty($request->getPost('disbursed_date')) ? date('Y-m-d', strtotime($request->getPost('disbursed_date'))) : null; $cheque_date = !empty($request->getPost('cheque_date')) ? date('Y-m-d', strtotime($request->getPost('cheque_date'))) : null; $bank_name = $request->getPost('bank_name'); $cheque_no = $request->getPost('cheque_no'); $disbursed_cheque_amount = str_replace(',', '', $request->getPost('disbursed_cheque_amount')); $remarks = $request->getPost('remarks'); $follow_up = $request->getPost('follow_up'); // Handle file upload $file_name = ""; if ($file = $request->getFile('cheque_scanned_copy')) { if ($file->isValid() && !$file->hasMoved()) { $newName = time() . '_' . $file->getRandomName(); $file->move('public/loan_uploads/', $newName); $file_name = $newName; } } // Timestamp for record creation $created_at = date('Y-m-d H:i:s', time()); $db = \Config\Database::connect(); $builder = $db->table('gss_loans'); $existing = $builder->where('booking_id', $booking_id)->get()->getRow(); if ($existing) { return $this->response->setJSON(['result' => 2, 'message' => "Details already exist. Please edit content"]); } // Update booking source type and bank name $db->table('gss_bookings')->where('booking_id', $booking_id)->update([ 'source_type' => $source_type, 'source_bank_name' => $source_bank_name ]); // Insert new loan details $loan_data = [ 'booking_id' => $booking_id, 'sale_agreement_amount' => $sale_agreement_amount, 'loan_amount_applied' => $loan_amount_applied, 'financial_institution' => $financial_institution, 'processing_fees' => $processing_fees, 'applied_on' => $applied_on, 'sanctioned_date' => $sanctioned_date, 'disbursed_date' => $disbursed_date, 'bank_name' => $bank_name, 'cheque_no' => $cheque_no, 'cheque_date' => $cheque_date, 'disbursed_cheque_amount' => $disbursed_cheque_amount, 'remarks' => $remarks, 'follow_up' => $follow_up, 'cheque_scanned_copy' => $file_name, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $inserted = $db->table('gss_loans')->insert($loan_data); if ($inserted) { return $this->response->setJSON(['result' => 1, 'message' => "Details added successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong. Try again."]); } } public function get_loan_details() { $gss_model=new Gss_model(); $booking_id = $this->request->getPost('booking_id'); $result = $gss_model->get_loan_details($booking_id); if($result) { return $this->response->setJSON(['result'=>1,'loan_details'=>$result]); } else { return $this->response->setJSON(['result'=>0]); } } public function edit_loan() { $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $admin_table = 'gss_login'; $table = 'gss_loans'; $loan_id = $this->request->getUri()->getSegment(2);; $data['loan_id'] = $this->request->getUri()->getSegment(2);; $where = ['loan_id' => $loan_id]; $where_admin = ['user_type_id' => '6']; $data['details'] = $gss_model->get_where_row($table,$where); $booking_id=$data['details']->booking_id; $booking_table = 'gss_bookings'; $where_booking = ['booking_id' => $booking_id]; $data['source_type'] = $gss_model->get_where_row($booking_table,$where_booking); $data['details'] = $gss_model->get_where_row($table,$where); $data['loan_admins'] = $gss_model->get_where_result($admin_table,$where_admin); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/edit_loan_form',$data); } else { redirect('/'); } } public function update_loan_details() { $gss_model=new Gss_model(); $loan_id = $this->request->getPost('loan_id'); $booking_id = $this->request->getPost('booking_id'); $sale_agreement_amount = str_replace(',', '', $this->request->getPost('sale_agreement_amount')); $loan_amount_applied = str_replace(',', '', $this->request->getPost('loan_amount_applied')); $financial_institution = $this->request->getPost('financial_institution'); $processing_fees = str_replace(',', '', $this->request->getPost('processing_fees')); $applied_on = $this->request->getPost('applied_on'); $source_type = $this->request->getPost('source_type'); $sanctioned_date = $this->request->getPost('sanctioned_date'); $disbursed_date = $this->request->getPost('disbursed_date'); $bank_name = $this->request->getPost('bank_name'); $cheque_no = $this->request->getPost('cheque_no'); $cheque_date = $this->request->getPost('cheque_date'); $disbursed_cheque_amount = str_replace(',', '', $this->request->getPost('disbursed_cheque_amount')); $remarks = $this->request->getPost('remarks'); $follow_up = $this->request->getPost('follow_up'); // Format dates $applied_on = $applied_on ? (new \DateTime($applied_on))->format('Y-m-d') : null; $sanctioned_date = $sanctioned_date ? (new \DateTime($sanctioned_date))->format('Y-m-d') : null; $disbursed_date = $disbursed_date ? (new \DateTime($disbursed_date))->format('Y-m-d') : null; $cheque_date = $cheque_date ? (new \DateTime($cheque_date))->format('Y-m-d') : null; // File upload $file = $this->request->getFile('cheque_scanned_copy'); $file_name = ''; if ($file && $file->isValid() && !$file->hasMoved()) { $file_name = time() . '_' . $file->getName(); $file->move('loan_uploads', $file_name); } else { $check_booking = $gss_model->get_where_row('gss_loans', ['loan_id' => $loan_id]); $file_name = $check_booking->cheque_scanned_copy ?? ''; } $data = [ 'booking_id' => $booking_id, 'sale_agreement_amount' => $sale_agreement_amount, 'loan_amount_applied' => $loan_amount_applied, 'financial_institution' => $financial_institution, 'processing_fees' => $processing_fees, 'applied_on' => $applied_on, 'sanctioned_date' => $sanctioned_date, 'disbursed_date' => $disbursed_date, 'bank_name' => $bank_name, 'cheque_no' => $cheque_no, 'cheque_date' => $cheque_date, 'disbursed_cheque_amount' => $disbursed_cheque_amount, 'remarks' => $remarks, 'follow_up' => $follow_up, 'cheque_scanned_copy' => $file_name, 'delete_status' => 'ACTIVE', 'updated_at' => date('Y-m-d H:i:s'), ]; // Update source_type if changed $db = \Config\Database::connect(); if ($source_type != "0") { $db->table('gss_bookings') ->where('booking_id', $booking_id) ->update(['source_type' => $source_type]); } $db->table('gss_loans') ->where('loan_id', $loan_id) ->update($data); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Details updated successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong.. try again"]); } } public function commission_form() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); // Fetch Associates $associates = $db->table('gss_brokers') ->where(['delete_status' => 'ACTIVE', 'type' => 'Associate']) ->get() ->getResult(); // Fetch Projects $projects = $db->table('gss_new_projects') ->where(['delete_status' => 'ACTIVE', 'project_status' => 'ONGOING']) ->get() ->getResult(); // Fetch Executives (Reference) $reference = $db->table('gss_brokers') ->where(['delete_status' => 'ACTIVE', 'type' => 'Executives']) ->get() ->getResult(); // Fetch Commission Notifications (Fixed Query) $notifications = $db->table('gss_commission_notifications A') ->select('A.*, B.*, C.*, D.*, A.delete_status as ad_s, B.delete_status as b_ds, C.delete_status as cd_s, D.delete_status as dd_s, E.delete_status as ed_s, E.registration_date, E.agreement_date, B.associate, F.associate_name, A.status as statuss') ->join('gss_bookings B', 'B.booking_id = A.booking_id') ->join('gss_new_projects C', 'C.project_id = B.project_id') ->join('gss_booking_details D', 'D.detail_id = A.detail_id') ->join('gss_plot_payments E', 'E.booking_id = A.booking_id') ->join('gss_brokers F', 'F.broker_id = B.associate') ->where([ 'A.delete_status' => 'ACTIVE', 'B.delete_status' => 'ACTIVE', 'C.delete_status' => 'ACTIVE', 'D.delete_status' => 'ACTIVE', 'E.delete_status' => 'ACTIVE', 'F.delete_status' => 'ACTIVE', 'A.status' => 'PENDING', 'B.booking_status' => 'BOOKED' ]) ->groupStart() ->where('A.commission_agreement', 'Available') ->orWhere('A.commission_registration', 'Available') ->groupEnd() ->groupBy('E.booking_id') ->orderBy('A.notification_id', 'DESC') ->get() ->getResult(); // Load View return view('admin/management', [ 'associates' => $associates, 'projects' => $projects, 'reference' => $reference, 'agreement' => $notifications, 'registration' => $notifications, 'user_type_id' => $this->access_id(), 'access' => $this->access_details() ]); } //Notifications public function notifications() { $db = \Config\Database::connect(); $builder = $db->table('gss_commission_notifications A') ->select('A.*, B.*, C.*, D.*, E.delete_status as ed_s, E.registration_date, E.agreement_date, B.associate, F.associate_name, A.status as statuss') ->join('gss_bookings B', 'B.booking_id = A.booking_id') ->join('gss_new_projects C', 'C.project_id = B.project_id') ->join('gss_booking_details D', 'D.detail_id = A.detail_id') ->join('gss_plot_payments E', 'E.booking_id = A.booking_id') ->join('gss_brokers F', 'F.broker_id = B.associate') ->where([ 'A.delete_status' => 'ACTIVE', 'B.delete_status' => 'ACTIVE', 'C.delete_status' => 'ACTIVE', 'D.delete_status' => 'ACTIVE', 'E.delete_status' => 'ACTIVE', 'F.delete_status' => 'ACTIVE', 'A.status' => 'PENDING', 'B.booking_status' => 'BOOKED' ]) ->groupStart() ->where('A.commission_agreement', 'Available') ->orWhere('A.commission_registration', 'Available') ->groupEnd() ->groupBy('E.booking_id') ->orderBy('A.notification_id', 'DESC'); $result = $builder->get()->getResult(); if ($result) { return $this->response->setJSON([ 'result' => 1, 'notifications' => $result, 'total' => count($result) ]); } else { return $this->response->setJSON(['result' => 0]); } } //Add management details public function add_management_details() { $db = \Config\Database::connect(); // 🔹 Get Input Values $booking_id = $this->request->getPost('booking_id'); $detail_id = $this->request->getPost('detail_id'); $total_commission_perc = (float) ($this->request->getPost('total_commission_perc') ?? 0); $total_commission_rs = (float) ($this->request->getPost('total_commission_rs') ?? 0); $payment_on_agreement = (float) ($this->request->getPost('payment_on_agreement') ?? 0); $payment_on_registration = (float) ($this->request->getPost('payment_on_registration') ?? 0); // 🔹 Convert Dates Safely $agreement_executed_on = $this->request->getPost('agreement_executed_on'); $agreement_executed_on = !empty($agreement_executed_on) ? date("Y-m-d", strtotime($agreement_executed_on)) : '0000-00-00'; $registration_on = $this->request->getPost('registration_on'); $registration_on = !empty($registration_on) ? date("Y-m-d", strtotime($registration_on)) : '0000-00-00'; $subagreement_executed_on = $this->request->getPost('subagreement_executed_on'); $subagreement_executed_on = !empty($subagreement_executed_on) ? date("Y-m-d", strtotime($subagreement_executed_on)) : '0000-00-00'; $subregistration_on = $this->request->getPost('subregistration_on'); $subregistration_on = !empty($subregistration_on) ? date("Y-m-d", strtotime($subregistration_on)) : '0000-00-00'; // 🔹 Get More Inputs (Ensure No NULL values) $subtotal_commission_perc = (float) ($this->request->getPost('subtotal_commission_perc') ?? 0); $subtotal_commission_rs = (float) ($this->request->getPost('subtotal_commission_rs') ?? 0); $subpayment_on_agreement = (float) ($this->request->getPost('subpayment_on_agreement') ?? 0); $subpayment_on_registration = (float) ($this->request->getPost('subpayment_on_registration') ?? 0); // 🔹 Created Timestamp $created_at = (new DateTime('now', new DateTimeZone('Asia/Kolkata')))->format('Y-m-d H:i:s'); // 🔹 Prepare Data for Insert $data = [ 'booking_id' => $booking_id, 'detail_id' => $detail_id, 'total_commission_perc' => $total_commission_perc, 'total_commission_rs' => $total_commission_rs, 'payment_on_agreement' => $payment_on_agreement, 'agreement_executed_on' => $agreement_executed_on, 'payment_on_registration' => $payment_on_registration, 'registration_on' => $registration_on, 'subtotal_commission_perc' => $subtotal_commission_perc, 'subtotal_commission_rs' => $subtotal_commission_rs, 'subpayment_on_agreement' => $subpayment_on_agreement, 'subagreement_executed_on' => $subagreement_executed_on, 'subpayment_on_registration'=> $subpayment_on_registration, 'subregistration_on' => $subregistration_on, 'agreement_status' => 'PENDING', 'registration_status' => 'PENDING', 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; // 🔹 Insert Data $result = $db->table('gss_management')->insert($data); if ($result) { $db->table('gss_commission_notifications') ->where('booking_id', $booking_id) ->update(['status' => 'APPROVED']); return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } //Commission form public function add_commission() { $db = \Config\Database::connect(); $admin_id = session()->get('admin_id'); if (!$admin_id) { return redirect('/'); } $uri = service('uri'); $booking_id = $uri->getSegment(2); // 🔹 Get Booking Details $data['details'] = $db->table('gss_bookings A') ->select('E.total_in_sqft, A.*, B.*, C.*') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->join('gss_booking_details C', 'C.booking_id = A.booking_id') ->join('gss_new_sites E', 'E.project_id = B.project_id AND C.site_number = E.site_number') ->where([ 'A.delete_status' => 'ACTIVE', 'B.delete_status' => 'ACTIVE', 'A.booking_id' => $booking_id, 'A.booking_status' => 'BOOKED' ]) ->orderBy('A.booking_id', 'DESC') ->get() ->getRow(); // 🔹 Get Executed Dates $data['dates'] = $db->table('gss_plot_payments') ->select('agreement_date, registration_date') ->where(['delete_status' => 'ACTIVE', 'booking_id' => $booking_id]) ->get() ->getRow(); // 🔹 Fetch Data for Dropdowns $data['projects'] = $db->table('gss_new_projects') ->where(['delete_status' => 'ACTIVE', 'project_status' => 'ONGOING']) ->orderBy('project_name', 'ASC') ->get() ->getResult(); $data['reference'] = $db->table('gss_brokers') ->where(['delete_status' => 'ACTIVE', 'type' => 'Executives']) ->orderBy('associate_name', 'ASC') ->get() ->getResult(); $data['associates'] = $db->table('gss_brokers') ->where(['delete_status' => 'ACTIVE', 'type' => 'Associate']) ->orderBy('associate_name', 'ASC') ->get() ->getResult(); $data['subassociates'] = $db->table('gss_brokers') ->where(['delete_status' => 'ACTIVE', 'type' => 'Sub Associate']) ->orderBy('associate_name', 'ASC') ->get() ->getResult(); // 🔹 Access Control Data $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); // 🔹 Load View return view('admin/add_commission_form', $data); } public function add_regcommission() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $uri = service('uri'); $booking_id = $uri->getSegment(2); // Fetch booking details $data['details'] = $db->table('gss_bookings A') ->select('E.total_in_sqft, A.*, B.*, C.*') ->join('gss_new_projects B', 'B.project_id = A.project_id', 'left') ->join('gss_booking_details C', 'C.booking_id = A.booking_id', 'left') ->join('gss_new_sites E', 'E.project_id = B.project_id AND C.site_number = E.site_number', 'left') ->where([ 'A.delete_status' => 'ACTIVE', 'B.delete_status' => 'ACTIVE', 'A.booking_id' => $booking_id, 'A.booking_status' => 'BOOKED' ]) ->orderBy('A.booking_id', 'DESC') ->get() ->getRow(); // Fetch executed dates $data['dates'] = $db->table('gss_plot_payments A') ->select('A.agreement_date, A.registration_date') ->where([ 'A.delete_status' => 'ACTIVE', 'A.booking_id' => $booking_id ]) ->get() ->getRow(); // Define conditions $where_project = ['delete_status' => 'ACTIVE', 'project_status' => 'ONGOING']; $where_reference = ['delete_status' => 'ACTIVE', 'type' => 'Executives']; $where_associate = ['delete_status' => 'ACTIVE', 'type' => 'Associate']; $where_subassociate = ['delete_status' => 'ACTIVE', 'type' => 'Sub Associate']; // Fetch related data $data['associates'] = $db->table('gss_brokers') ->select('*') ->where($where_associate) ->get() ->getResult(); $data['subassociates'] = $db->table('gss_brokers') ->select('*') ->where($where_subassociate) ->get() ->getResult(); $data['projects'] = $db->table('gss_new_projects') ->select('*') ->where($where_project) ->get() ->getResult(); $data['reference'] = $db->table('gss_brokers') ->select('*') ->where($where_reference) ->get() ->getResult(); // Format date helper function directly in the controller $formatDate = function ($date) { return $date ? date("Y-m-d", strtotime($date)) : null; }; // Access permissions $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/add_regcommission_form', $data); } //Commission list public function commission_list() { $admin_id = session()->get('admin_id'); if($admin_id) { $GssNewProjectsModel = new GssNewProjectsModel(); $BrokerModel = new BrokerModel(); $broker_table = 'gss_brokers'; $project_table = 'gss_new_projects'; $where_project = array('delete_status'=>'ACTIVE','project_status'=>'ONGOING'); $where_reference = array('delete_status'=>'ACTIVE','type'=>'Executives'); $where_associate = array('delete_status'=>'ACTIVE','type'=>'Associate'); $data['associates'] = $BrokerModel->get_where_result($broker_table,$where_associate); $data['projects'] = $GssNewProjectsModel->get_where_result($project_table,$where_project); $data['reference'] = $BrokerModel->get_where_result($broker_table,$where_reference); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/commission_list',$data); } else { redirect('/'); } } //Approve commission public function approve_reg_commission() { $db = \Config\Database::connect(); $management_id = $this->request->getPost('management_id'); // Get current timestamp $updated_at = (new DateTime('now', new DateTimeZone('Asia/Kolkata')))->format('Y-m-d H:i:s'); // Data to update $data = [ 'registration_status' => 'APPROVED', 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ]; // Update Query $builder = $db->table('gss_management'); $builder->where('management_id', $management_id); $builder->update($data); // Check affected rows if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Approved successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Failed to approve. Try again"]); } } public function dis_approve_reg_commission() { $db = \Config\Database::connect(); $management_id = $this->request->getPost('management_id'); // Get current timestamp $updated_at = (new DateTime('now', new DateTimeZone('Asia/Kolkata')))->format('Y-m-d H:i:s'); // Data to update $data = [ 'registration_status' => 'PENDING', 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ]; // Update Query $builder = $db->table('gss_management'); $builder->where('management_id', $management_id); $builder->update($data); // Check affected rows if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Disapproved successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Failed to disapprove. Try again"]); } } public function approve_aggr_commission() { $db = \Config\Database::connect(); $management_id = $this->request->getPost('management_id'); // Get current timestamp $updated_at = (new DateTime('now', new DateTimeZone('Asia/Kolkata')))->format('Y-m-d H:i:s'); // Data to update $data = [ 'agreement_status' => 'APPROVED', 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ]; // Update Query $builder = $db->table('gss_management'); $builder->where('management_id', $management_id); $builder->update($data); // Check affected rows if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Approved successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Failed to approve. Try again"]); } } public function dis_approve_aggr_commission() { $db = \Config\Database::connect(); $management_id = $this->request->getPost('management_id'); // Get current timestamp $updated_at = (new DateTime('now', new DateTimeZone('Asia/Kolkata')))->format('Y-m-d H:i:s'); // Data to update $data = [ 'agreement_status' => 'PENDING', 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ]; // Update Query $builder = $db->table('gss_management'); $builder->where('management_id', $management_id); $builder->update($data); // Check affected rows if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Disapproved successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Failed to disapprove. Try again"]); } } public function edit_agreecommission() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $uri = service('uri'); $management_id = $uri->getSegment(2); // 🔹 Fetch Data for Dropdowns $data['associates'] = $db->table('gss_brokers') ->where(['delete_status' => 'ACTIVE', 'type' => 'Associate']) ->get()->getResult(); $data['subassociates'] = $db->table('gss_brokers') ->where(['delete_status' => 'ACTIVE', 'type' => 'Sub Associate']) ->get()->getResult(); $data['projects'] = $db->table('gss_new_projects') ->where(['delete_status' => 'ACTIVE', 'project_status' => 'ONGOING']) ->get()->getResult(); $data['reference'] = $db->table('gss_brokers') ->where(['delete_status' => 'ACTIVE', 'type' => 'Executives']) ->get()->getResult(); // 🔹 Fetch Commission Details $data['commission'] = $db->table('gss_management A') ->select('E.total_in_sqft, A.*, B.*, C.*, D.*') ->join('gss_bookings B', 'B.booking_id = A.booking_id') ->join('gss_booking_details C', 'C.detail_id = A.detail_id') ->join('gss_new_projects D', 'D.project_id = B.project_id') ->join('gss_new_sites E', 'E.project_id = D.project_id AND C.site_number = E.site_number') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('C.delete_status', 'ACTIVE') ->where('D.delete_status', 'ACTIVE') ->where('A.management_id', $management_id) ->get()->getRow(); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/edit_commission', $data); } public function edit_regcommission() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $uri=service('uri'); $management_id = $uri->getSegment(2); // 🔹 Fetch Associates $data['associates'] = $db->table('gss_brokers') ->where(['delete_status' => 'ACTIVE', 'type' => 'Associate']) ->get()->getResult(); // 🔹 Fetch Sub-Associates $data['subassociates'] = $db->table('gss_brokers') ->where(['delete_status' => 'ACTIVE', 'type' => 'Sub Associate']) ->get()->getResult(); // 🔹 Fetch Ongoing Projects $data['projects'] = $db->table('gss_new_projects') ->where(['delete_status' => 'ACTIVE', 'project_status' => 'ONGOING']) ->get()->getResult(); // 🔹 Fetch References $data['reference'] = $db->table('gss_brokers') ->where(['delete_status' => 'ACTIVE', 'type' => 'Executives']) ->get()->getResult(); // 🔹 Fetch Commission Details $data['commission'] = $db->table('gss_management A') ->select('E.total_in_sqft, A.*, B.*, C.*, D.*') ->join('gss_bookings B', 'B.booking_id = A.booking_id') ->join('gss_booking_details C', 'C.detail_id = A.detail_id') ->join('gss_new_projects D', 'D.project_id = B.project_id') ->join('gss_new_sites E', 'E.project_id = D.project_id AND C.site_number = E.site_number') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('C.delete_status', 'ACTIVE') ->where('D.delete_status', 'ACTIVE') ->where('A.management_id', $management_id) ->get()->getRow(); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/edit_regcommission', $data); } public function delete_commission() { $db = \Config\Database::connect(); $management_id = $this->request->getPost('management_id'); if (!$management_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid ID provided']); } $updated_at = date('Y-m-d H:i:s', time()); // Update delete_status to 'INACTIVE' $update = $db->table('gss_management') ->where('management_id', $management_id) ->update(['delete_status' => 'INACTIVE', 'updated_at' => $updated_at]); if ($update) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to delete. Try again']); } } public function update_commission() { $db = \Config\Database::connect(); $management_id = $this->request->getPost('management_id'); $booking_id = $this->request->getPost('booking_id'); $detail_id = $this->request->getPost('detail_id'); $total_commission_perc = $this->request->getPost('total_commission_perc'); $total_commission_rs = $this->request->getPost('total_commission_rs'); $payment_on_agreement = $this->request->getPost('payment_on_agreement'); $payment_on_registration = $this->request->getPost('payment_on_registration'); $registration_on = $this->request->getPost('registration_on'); $subtotal_commission_perc = $this->request->getPost('subtotal_commission_perc'); $subtotal_commission_rs = $this->request->getPost('subtotal_commission_rs'); $subpayment_on_agreement = $this->request->getPost('subpayment_on_agreement'); $subagreement_executed_on = $this->request->getPost('subagreement_executed_on'); $agreement_executed_on = $this->request->getPost('agreement_executed_on'); $agreement_status = $this->request->getPost('agreement_status'); $registration_status = $this->request->getPost('registration_status'); // Convert date formats $registration_on = (!empty($registration_on)) ? date('Y-m-d', strtotime($registration_on)) : null; $agreement_executed_on = (!empty($agreement_executed_on)) ? date('Y-m-d', strtotime($agreement_executed_on)) : null; $updated_at = date('Y-m-d H:i:s'); // Current timestamp // Data to update $data = [ 'booking_id' => $booking_id, 'detail_id' => $detail_id, 'total_commission_perc' => $total_commission_perc, 'total_commission_rs' => $total_commission_rs, 'payment_on_agreement' => $payment_on_agreement, 'payment_on_registration' => $payment_on_registration, 'agreement_executed_on' => $agreement_executed_on, 'registration_on' => $registration_on, 'subtotal_commission_perc' => $subtotal_commission_perc, 'subtotal_commission_rs' => $subtotal_commission_rs, 'subpayment_on_agreement' => $subpayment_on_agreement, 'subagreement_executed_on' => $subagreement_executed_on, 'subregistration_on' => $registration_on, 'agreement_status' => $agreement_status, 'registration_status' => $registration_status, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ]; // Update query $update = $db->table('gss_management') ->where('booking_id', $booking_id) ->update($data); if ($update) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong.. try again']); } } public function management_list() { $db = \Config\Database::connect(); $builder = $this->db->table('gss_management A') ->select('A.*, B.*, C.*, D.*, A.created_at as commission_date') ->join('gss_bookings B', 'B.booking_id = A.booking_id') ->join('gss_booking_details C', 'C.detail_id = A.detail_id') ->join('gss_new_projects D', 'D.project_id = B.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('C.delete_status', 'ACTIVE') ->where('D.delete_status', 'ACTIVE') ->groupBy('A.booking_id') ->orderBy('A.management_id', 'DESC'); $result = $builder->get()->getResult(); $array = []; foreach ($result as $val) { $data = [ 'booking_id' => $val->booking_id, 'commission_date' => $val->commission_date, 'management_id' => $val->management_id, 'project_name' => $val->project_name, 'site_number' => $val->site_number, 'total_commission_perc' => $val->total_commission_perc, 'total_commission_rs' => $val->total_commission_rs ]; // Fetch Associate Name $associate = $this->db->table('gss_brokers A') ->select('A.associate_name') ->where('A.delete_status', 'ACTIVE') ->where('A.broker_id', $val->associate) ->get() ->getRow(); $data['associate'] = $associate ? $associate->associate_name : ''; // Fetch Sub-Associate Name $subassociate = $this->db->table('gss_brokers A') ->select('A.associate_name') ->where('A.delete_status', 'ACTIVE') ->where('A.broker_id', $val->subassociate) ->get() ->getRow(); $data['subassociate'] = $subassociate ? $subassociate->associate_name : ''; // Fetch Agreement Details $agreement = $this->db->table('gss_management A') ->select('A.management_id, A.agreement_executed_on, A.payment_on_agreement, A.agreement_status') ->where('A.delete_status', 'ACTIVE') ->where('A.booking_id', $val->booking_id) ->get() ->getRow(); if ($agreement) { $data['payment_on_agreement'] = $agreement->payment_on_agreement; $data['agreement_executed_on'] = $agreement->agreement_executed_on; $data['agreement_status'] = $agreement->agreement_status; $data['agreement_approval'] = ($agreement->agreement_status == "PENDING") ? 'Approve' : 'Disapprove'; } else { $data['payment_on_agreement'] = ''; $data['agreement_executed_on'] = ''; $data['agreement_status'] = ''; $data['agreement_approval'] = ''; } // Fetch Registration Details $registration = $this->db->table('gss_management A') ->select('A.management_id, A.payment_on_registration, A.registration_on, A.registration_status') ->where('A.delete_status', 'ACTIVE') ->where('A.booking_id', $val->booking_id) ->get() ->getRow(); if ($registration) { $data['payment_on_registration'] = $registration->payment_on_registration; $data['registration_on'] = $registration->registration_on; $data['registration_status'] = $registration->registration_status; $data['registration_approval'] = ($registration->registration_status == "PENDING") ? 'Approve' : 'Disapprove'; } else { $data['payment_on_registration'] = ''; $data['registration_on'] = ''; $data['registration_status'] = ''; $data['registration_approval'] = ''; } if (!empty($data['associate'])) { array_push($array, $data); } } if (!empty($array)) { return $this->response->setJSON($array); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No data available']); } } //Reception form public function reception_form() { $admin_id = session()->get('admin_id'); if($admin_id) { $GssNewProjectsModel = new GssNewProjectsModel(); $project_table = 'gss_new_projects'; $where_project = array('delete_status'=>'ACTIVE'); $order_by = 'project_name'; $data['projects'] = $GssNewProjectsModel->get_where_result_alphabetical($project_table,$where_project,$order_by); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/reception_form',$data); } else { redirect('/'); } } //Add reception detailss public function add_reception_details() { $request = \Config\Services::request(); // Load request service $db = \Config\Database::connect(); // Load database connection $booking_id = $request->getPost('booking_id'); $detail_id = $request->getPost('detail_id'); $project_id = $request->getPost('project_id'); $site_number = $request->getPost('site_number'); $customer_name = $request->getPost('customer_name'); $client_khatha = $request->getPost('client_khatha'); $dispatched_type = $request->getPost('dispatched_type'); $dispatched_date = $request->getPost('dispatched_date'); if ($dispatched_date) { $date = new DateTime($dispatched_date); $dispatched_date = $date->format('Y-m-d'); } // File Upload Handling $uploadsDir ='public/reception_uploads/'; if (!is_dir($uploadsDir)) { mkdir($uploadsDir, 0777, true); // Create folder if not exists } // Function to upload file $uploadFile = function ($field) use ($uploadsDir) { $file = $this->request->getFile($field); if ($file && $file->isValid() && !$file->hasMoved()) { $newName = time() . "_" . $file->getClientName(); $file->move($uploadsDir, $newName); return $newName; } return ""; }; $nine_and_eleven_copy = $uploadFile('nine_and_eleven_copy'); $muda_khatha = $uploadFile('muda_khatha'); $other_document = $uploadFile('other_document'); // Current timestamp $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); // Data array $data = [ 'booking_id_fk' => $booking_id, 'detail_id_fk' => $detail_id, 'project_id' => $project_id, 'site_number' => $site_number, 'nine_and_eleven_copy' => $nine_and_eleven_copy, 'muda_khatha' => $muda_khatha, 'other_document' => $other_document, 'client_name' => $customer_name, 'client_khatha' => $client_khatha, 'dispatched_type' => $dispatched_type, 'dispatched_date' => $dispatched_date, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $table = 'gss_reception'; // Function to get a single row from the database $get_where_row = function ($table, $where) use ($db) { return $db->table($table)->where($where)->get()->getRow(); }; $where = ['project_id' => $project_id, 'site_number' => $site_number, 'delete_status' => 'ACTIVE']; $check_booking = $get_where_row($table, $where); if ($check_booking) { return $this->response->setJSON(['result' => 2, 'message' => "Details already exist. Please edit content"]); } else { $result = $db->table($table)->insert($data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => "Details added successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong. Try again"]); } } } //Reception list form public function reception_list() { $admin_id = session()->get('admin_id'); if($admin_id) { $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/reception_list',$data); } else { redirect('/'); } } //Reception list public function get_reception_list() { $builder = $this->db->table('gss_reception A') ->select('A.*, B.*, A.site_number as st_no') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->orderBy('A.site_number', 'ASC'); $result = $builder->get()->getResult(); $array = []; foreach ($result as $value) { $data = [ 'reception_id' => $value->reception_id, 'customer_name' => $value->client_name, 'client_khatha' => $value->client_khatha, 'dispatched_type' => $value->dispatched_type, 'dispatched_date' => $value->dispatched_date, 'project_name' => $value->project_name, 'site_number' => $value->st_no ]; array_push($array, $data); } if (!empty($array)) { return $this->response->setJSON($array); } else { return $this->response->setJSON(['result' => 0]); } } //Delete reception public function delete_reception() { $table = 'gss_reception'; $reception_id = $this->request->getPost('reception_id'); if (empty($reception_id)) { return $this->response->setJSON(['result' => 0, 'message' => 'Reception ID is required']); } $db = \Config\Database::connect(); $builder = $db->table($table); $builder->where('reception_id', $reception_id)->update(['delete_status' => 'INACTIVE']); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No changes made or invalid ID']); } } //Edit reception public function edit_reception_details() { $session = session(); $admin_id = $session->get('admin_id'); if ($admin_id) { $db = \Config\Database::connect(); $uri = service('uri'); // Fetch Projects $project_table = 'gss_new_projects'; $where_project = ['delete_status' => 'ACTIVE']; $order_by = 'project_name'; $data['projects'] = $db->table($project_table) ->where($where_project) ->orderBy($order_by, "ASC") ->get() ->getResult(); // Fetch Reception Details $reception_id = $uri->getSegment(2); $data['result'] = $db->table('gss_reception') ->where('delete_status', 'ACTIVE') ->where('reception_id', $reception_id) ->get() ->getRow(); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/edit_reception', $data); } else { return redirect()->to('/'); } } //Edit reception for non booked sites public function edit_reception() { $session = session(); $admin_id = $session->get('admin_id'); if ($admin_id) { $db = \Config\Database::connect(); $uri = service('uri'); // Correct way to get URI segment in CI4 // Get Reception ID from URI $reception_id = $uri->getSegment(2); // Fetch Active Projects $project_table = 'gss_new_projects'; $where_project = ['delete_status' => 'ACTIVE']; $data['projects'] = $db->table($project_table) ->where($where_project) ->get() ->getResult(); // Fetch Reception Details $data['result'] = $db->table('gss_reception') ->where('delete_status', 'ACTIVE') ->where('reception_id', $reception_id) ->get() ->getRow(); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/not_booked_edit_reception', $data); } else { return redirect()->to('/'); } } //Update reception detailss public function update_reception() { $db = \Config\Database::connect(); $request = service('request'); $reception_id = $request->getPost('reception_id'); $booking_id = $request->getPost('booking_id'); $detail_id = $request->getPost('detail_id'); $project_id = $request->getPost('project_id'); $site_number = $request->getPost('site_number'); $customer_name = $request->getPost('customer_name'); $client_khatha = $request->getPost('client_khatha'); $dispatched_type = $request->getPost('dispatched_type'); $dispatched_date = $request->getPost('dispatched_date'); if (!empty($dispatched_date)) { $date = new DateTime($dispatched_date); $dispatched_date = $date->format('Y-m-d'); } $table = 'gss_reception'; $where = ['reception_id' => $reception_id]; // Function to get a single row based on condition $get_where_row = function($db, $table, $where) { return $db->table($table) ->where($where) ->get() ->getRow(); }; // Function to handle file upload $uploadFile = function($field, $existingFile) { if (!empty($_FILES[$field]['name'])) { $uploadsDir = 'public/reception_uploads/'; $newName = time() . "_" . $_FILES[$field]['name']; $target = $uploadsDir . $newName; if (move_uploaded_file($_FILES[$field]['tmp_name'], $target)) { return $newName; } } return $existingFile; }; // Fetch existing files if new ones are not uploaded $existingData = $get_where_row($db, $table, $where); $nine_and_eleven_copy = $uploadFile('nine_and_eleven_copy', $existingData->nine_and_eleven_copy ?? ''); $muda_khatha = $uploadFile('muda_khatha', $existingData->muda_khatha ?? ''); $other_document = $uploadFile('other_document', $existingData->other_document ?? ''); // Get current timestamp $created_at = date('Y-m-d H:i:s', time()); // Data for update $data = [ 'booking_id_fk' => $booking_id, 'detail_id_fk' => $detail_id, 'project_id' => $project_id, 'site_number' => $site_number, 'nine_and_eleven_copy' => $nine_and_eleven_copy, 'muda_khatha' => $muda_khatha, 'other_document' => $other_document, 'client_name' => $customer_name, 'client_khatha' => $client_khatha, 'dispatched_type' => $dispatched_type, 'dispatched_date' => $dispatched_date, 'delete_status' => 'ACTIVE', 'updated_at' => $created_at ]; // Update the database $db->table($table)->where($where)->update($data); // Check affected rows if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Updated successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong.. try again"]); } } //Reception reports public function get_reception_reports() { $db = \Config\Database::connect(); // Get parameters from GET request $from_date = $this->request->getGet('from_date'); $to_date = $this->request->getGet('to_date'); $project_id = $this->request->getGet('project_id'); // Convert dates to proper format if provided if (!empty($from_date)) { $from_date = date('Y-m-d', strtotime($from_date)); } if (!empty($to_date)) { $to_date = date('Y-m-d', strtotime($to_date)); } // Initialize Query Builder $builder = $db->table('gss_reception A') ->select('B.project_name, A.client_name, A.booking_id_fk, A.detail_id_fk, A.project_id, A.site_number, A.dispatched_type, A.dispatched_date, A.client_khatha, A.created_at as reception_at') ->join('gss_new_projects B', 'A.project_id = B.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE'); // Apply filters if provided if (!empty($from_date)) { $builder->where('DATE(A.created_at) >=', $from_date); } if (!empty($to_date)) { $builder->where('DATE(A.created_at) <=', $to_date); } if (!empty($project_id)) { $builder->where('A.project_id', $project_id); } // Execute Query $builder->orderBy('B.project_name ASC, ABS(A.site_number) ASC'); $result = $builder->get()->getResult(); // Initialize response array $data_array = []; foreach ($result as $row) { $data = [ 'booking_id' => '', 'customer_name' => $row->client_name, 'address' => '', 'customer_mobile' => '', 'customer_email' => '', 'project_name' => $row->project_name, 'site_number' => $row->site_number, 'dimension' => '', 'booked_on' => '', 'booking_status' => '', 'dispatched_type' => $row->dispatched_type, 'dispatched_date' => $row->dispatched_date, 'reception_at' => $row->reception_at, 'client_khatha' => $row->client_khatha, ]; // If booking_id_fk and detail_id_fk exist, fetch additional details if ($row->booking_id_fk > 0 && $row->detail_id_fk > 0) { $booking = $db->table('gss_bookings A') ->select('A.booking_id, A.customer_name, A.address, A.mobile1, A.mobile2, A.email, A.booking_status, B.dimension, B.booking_date1') ->join('gss_booking_details B', 'A.booking_id = B.booking_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('A.booking_status', 'BOOKED') ->where('B.site_number', $row->site_number) ->where('B.project_id', $row->project_id) ->get() ->getRow(); if ($booking) { $data['booking_id'] = $booking->booking_id; $data['customer_name'] = $booking->customer_name; $data['address'] = $booking->address; $data['customer_mobile'] = $booking->mobile1; $data['customer_mobile2'] = $booking->mobile2; $data['customer_email'] = $booking->email; $data['dimension'] = $booking->dimension; $data['booked_on'] = $booking->booking_date1; $data['booking_status'] = $booking->booking_status; } } // Add to final response array $data_array[] = $data; } // Return JSON response return $this->response->setJSON($data_array); } public function get_reception_contact_reports() { $db = \Config\Database::connect(); // Get query parameters safely $from_date = $this->request->getGet('from_date'); $to_date = $this->request->getGet('to_date'); $project_id = $this->request->getGet('project_id'); // Convert date format if (!empty($from_date)) { $from_date = date('Y-m-d', strtotime($from_date)); } if (!empty($to_date)) { $to_date = date('Y-m-d', strtotime($to_date)); } // Build query for reception reports $builder = $db->table('gss_reception A') ->select('B.project_name, A.client_name, A.booking_id_fk, A.detail_id_fk, A.project_id, A.site_number, A.dispatched_type, A.dispatched_date, A.client_khatha, A.created_at as reception_at') ->join('gss_new_projects B', 'A.project_id = B.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE'); // Apply filters if provided if (!empty($from_date)) { $builder->where('DATE(A.created_at) >=', $from_date); } if (!empty($to_date)) { $builder->where('DATE(A.created_at) <=', $to_date); } if (!empty($project_id)) { $builder->where('A.project_id', $project_id); } $builder->orderBy('B.project_name ASC, ABS(A.site_number) ASC'); $result = $builder->get()->getResult(); // Process results $data_array = []; foreach ($result as $row) { $data = [ 'booking_id' => '', 'customer_name' => $row->client_name, 'address' => '', 'customer_mobile' => '', 'customer_email' => '', 'project_name' => $row->project_name, 'site_number' => $row->site_number, 'dimension' => '', 'booked_on' => '', 'booking_status' => '', 'dispatched_type' => $row->dispatched_type, 'dispatched_date' => $row->dispatched_date, 'reception_at' => $row->reception_at, 'client_khatha' => $row->client_khatha, ]; // Fetch booking details if applicable if ($row->booking_id_fk > 0 && $row->detail_id_fk > 0) { $booking = $db->table('gss_bookings A') ->select('A.booking_id, A.customer_name, A.address, A.mobile1, A.mobile2, A.email, A.booking_status, B.dimension, B.booking_date1') ->join('gss_booking_details B', 'A.booking_id = B.booking_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('A.booking_status', 'BOOKED') ->where('B.site_number', $row->site_number) ->where('B.project_id', $row->project_id) ->get() ->getRow(); if ($booking) { $data['booking_id'] = $booking->booking_id; $data['customer_name'] = $booking->customer_name; $data['address'] = $booking->address; $data['customer_mobile'] = $booking->mobile1; $data['customer_mobile2'] = $booking->mobile2; $data['customer_email'] = $booking->email; $data['dimension'] = $booking->dimension; $data['booked_on'] = $booking->booking_date1; $data['booking_status'] = $booking->booking_status; } } $data_array[] = $data; } return $this->response->setJSON($data_array); } public function get_reception_email_reports() { $db = \Config\Database::connect(); // Get query parameters safely $from_date = $this->request->getGet('from_date'); $to_date = $this->request->getGet('to_date'); $project_id = $this->request->getGet('project_id'); // Convert date format if (!empty($from_date)) { $from_date = date('Y-m-d', strtotime($from_date)); } if (!empty($to_date)) { $to_date = date('Y-m-d', strtotime($to_date)); } // Build query for reception email reports $builder = $db->table('gss_reception A') ->select('B.project_name, A.client_name, A.booking_id_fk, A.detail_id_fk, A.project_id, A.site_number, A.dispatched_type, A.dispatched_date, A.client_khatha, A.created_at as reception_at') ->join('gss_new_projects B', 'A.project_id = B.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE'); // Apply filters if provided if (!empty($from_date)) { $builder->where('DATE(A.created_at) >=', $from_date); } if (!empty($to_date)) { $builder->where('DATE(A.created_at) <=', $to_date); } if (!empty($project_id)) { $builder->where('A.project_id', $project_id); } $builder->orderBy('B.project_name ASC, ABS(A.site_number) ASC'); $result = $builder->get()->getResult(); // Process results $data_array = []; foreach ($result as $row) { $data = [ 'booking_id' => '', 'customer_name' => $row->client_name, 'address' => '', 'customer_mobile' => '', 'customer_email' => '', 'project_name' => $row->project_name, 'site_number' => $row->site_number, 'dimension' => '', 'booked_on' => '', 'booking_status' => '', 'dispatched_type' => $row->dispatched_type, 'dispatched_date' => $row->dispatched_date, 'reception_at' => $row->reception_at, 'client_khatha' => $row->client_khatha, ]; // Fetch booking details if applicable if ($row->booking_id_fk > 0 && $row->detail_id_fk > 0) { $booking = $db->table('gss_bookings A') ->select('A.booking_id, A.customer_name, A.address, A.mobile1, A.mobile2, A.email, A.booking_status, B.dimension, B.booking_date1') ->join('gss_booking_details B', 'A.booking_id = B.booking_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('A.booking_status', 'BOOKED') ->where('B.site_number', $row->site_number) ->where('B.project_id', $row->project_id) ->get() ->getRow(); if ($booking) { $data['booking_id'] = $booking->booking_id; $data['customer_name'] = $booking->customer_name; $data['address'] = $booking->address; $data['customer_mobile'] = $booking->mobile1; $data['customer_mobile2'] = $booking->mobile2; $data['customer_email'] = $booking->email; $data['dimension'] = $booking->dimension; $data['booked_on'] = $booking->booking_date1; $data['booking_status'] = $booking->booking_status; } } $data_array[] = $data; } return $this->response->setJSON($data_array); } public function details_for_management() { $db = \Config\Database::connect();// Database connection $site_number = $this->request->getPost('site_number'); $project_id = $this->request->getPost('project_id'); if (!$site_number || !$project_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Missing parameters']); } $check_site = $db->table('gss_new_sites A') ->select('A.*, B.*') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('A.site_number', $site_number) ->where('A.project_id', $project_id) ->get() ->getRow(); if ($check_site) { // Query: Get booking details $site_result = $db->table('gss_bookings A') ->select('A.*, B.*, C.*') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->join('gss_booking_details C', 'C.booking_id = A.booking_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('C.site_number', $site_number) ->where('C.project_id', $project_id) ->orderBy('A.booking_id', 'DESC') ->get() ->getRow(); if ($site_result) { $booking_id = $site_result->booking_id; // Query: Get agreement & registration dates $dates = $db->table('gss_plot_payments A') ->select('A.agreement_date, A.registration_date') ->where('A.delete_status', 'ACTIVE') ->where('A.booking_id', $booking_id) ->get() ->getRow(); if ($site_result->booking_status == 'CANCELLED') { return $this->response->setJSON([ 'result' => 3, 'message' => "Site number $site_number has been cancelled" ]); } else { return $this->response->setJSON([ 'result' => 1, 'booking_details' => $site_result, 'dates' => $dates ]); } } else { return $this->response->setJSON([ 'result' => 0, 'message' => "Site number $site_number not booked" ]); } } else { return $this->response->setJSON([ 'result' => 2, 'message' => "Site number $site_number not found" ]); } } public function new_reception_form() { $admin_id = session()->get('admin_id'); if($admin_id) { $GssNewProjectsModel= new GssNewProjectsModel(); $project_table = 'gss_new_projects'; $order_by = 'project_name'; $where_project = array('delete_status'=>'ACTIVE','project_status'=>'ONGOING'); $data['projects'] = $GssNewProjectsModel->get_where_result_alphabetical($project_table,$where_project,$order_by); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/new_reception_form',$data); } else { redirect('/'); } } public function check_cancelled_refunded_site_details() { // $db = Database::connect(); // Load the database $db = \Config\Database::connect(); $site_number = $this->request->getPost('site_number'); $project_id = $this->request->getPost('project_id'); // Check if site exists $check_site = $db->table('gss_new_sites A') ->select('A.*, B.*') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('A.site_number', $site_number) ->where('A.project_id', $project_id) ->get() ->getRow(); if ($check_site) { // Get site payment details $get_site = $db->table('gss_bookings A') ->select('A.booking_id as booking_id1, A.*, B.booking_id as booking_id2, B.*, B.detail_id, C.project_id, C.project_name, C.nick_name, D.total_in_sqft, E.*') ->join('gss_booking_details B', 'B.booking_id = A.booking_id') ->join('gss_new_projects C', 'C.project_id = A.project_id') ->join('gss_new_sites D', 'D.project_id = C.project_id') ->join('gss_plot_payments E', 'E.booking_id = A.booking_id', 'left') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('C.delete_status', 'ACTIVE') ->where('D.delete_status', 'ACTIVE') ->where('A.project_id', $project_id) ->where('B.site_number', $site_number) ->where('A.booking_status !=', 'CANCELLED') ->orderBy('A.booking_id', 'DESC') ->get() ->getRow(); if ($get_site) { if ($get_site->booking_status == 'CANCELLED') { return $this->response->setJSON(['result' => 3, 'message' => "Site number $site_number has been cancelled"]); } elseif ($get_site->booking_status == 'REFUNDED') { return $this->response->setJSON(['result' => 3, 'message' => "Site number $site_number has been refunded"]); } else { $where_booking = ['booking_id' => $get_site->booking_id, 'delete_status' => 'ACTIVE']; $instal_result = $db->table('gss_plot_payments')->where($where_booking)->get()->getResult(); $agree_result = $db->table('gss_plot_payments')->where($where_booking)->get()->getRow(); $get_reg_amt = $db->table('gss_registration_amount_details')->where($where_booking)->get()->getResult(); $get_due_amount = $db->table('gss_cancellations')->where($where_booking)->get()->getResult(); $agr_amount = $db->table('gss_plot_payments')->where($where_booking)->get()->getResult(); return $this->response->setJSON([ 'result' => 1, 'booking_details' => $get_site, 'installments' => $instal_result, 'agree' => $agree_result, 'reg_amount' => $get_reg_amt, 'due_amount' => $get_due_amount, 'payment_agr_amount' => $agr_amount ]); } } else { return $this->response->setJSON(['result' => 0, 'message' => "Site number $site_number not booked"]); } } else { return $this->response->setJSON(['result' => 2, 'message' => "Site number $site_number not found"]); } } public function get_reception_reports_datewise() { $db = \Config\Database::connect(); // Load database $project = $this->request->getGet('project'); $from_date = $this->request->getGet('from_date'); $to_date = $this->request->getGet('to_date'); $builder = $db->table('gss_new_receptions A') ->select('A.*, B.*') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE'); if (!empty($project)) { $builder->where('A.project_id', $project); } if (!empty($from_date)) { $builder->where("STR_TO_DATE(A.dispatched_date,'%d-%m-%Y') >= STR_TO_DATE('$from_date','%d-%m-%Y')"); } if (!empty($to_date)) { $builder->where("STR_TO_DATE(A.dispatched_date,'%d-%m-%Y') <= STR_TO_DATE('$to_date','%d-%m-%Y')"); } $result = $builder->get()->getResult(); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0]); } } public function add_new_reception_details() { $session = session(); $admin_id = $session->get('admin_id'); if ($admin_id) { $db = \Config\Database::connect(); $request = service('request'); $project_id = $request->getPost('project_id'); $booking_id = $request->getPost('booking_id'); $detail_id = $request->getPost('detail_id'); $site_number = $request->getPost('site_number'); $site_dimension = $request->getPost('site_dimension'); $customer_name = $request->getPost('customer_name'); $contact1 = $request->getPost('contact1'); $contact2 = $request->getPost('contact2'); $dispatched = $request->getPost('dispatched'); $dispatched_date = $request->getPost('dispatched_date'); $doc_details = $request->getPost('doc_details'); $ack_doc = $request->getPost('ack_doc'); $remarks = $request->getPost('remarks'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $table = 'gss_new_receptions'; // Check if details already exist $check_details = $db->table($table) ->where([ 'project_id' => $project_id, 'site_number' => $site_number, 'delete_status' => 'ACTIVE' ]) ->get() ->getResult(); if ($check_details) { return $this->response->setJSON(['result' => 0, 'message' => "Details already exist"]); } // Insert new reception details $data = [ 'detail_id' => $detail_id, 'booking_id' => $booking_id, 'project_id' => $project_id, 'site_number' => $site_number, 'site_dimension' => $site_dimension, 'customer_name' => $customer_name, 'contact1' => $contact1, 'contact2' => $contact2, 'dispatched' => $dispatched, 'dispatched_date' => $dispatched_date, 'doc_details' => $doc_details, 'ack_doc' => $ack_doc, 'remarks' => $remarks, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $db->table($table)->insert($data); $inserted_id = $db->insertID(); if ($inserted_id) { return $this->response->setJSON(['result' => 1, 'message' => "Added successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong.. try again"]); } } else { return redirect()->to('/'); } } public function new_reception_list() { $admin_id = session()->get('admin_id'); if($admin_id) { $GssNewProjectsModel= new GssNewProjectsModel(); $project_table = 'gss_new_projects'; $projects_order_by = 'project_name'; $where_project = array('delete_status'=>'ACTIVE'); $data['projects'] = $GssNewProjectsModel->get_where_result_orderby_asc($project_table,$where_project,$projects_order_by); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/new_reception_list',$data); } else { redirect('/'); } } public function get_new_reception_list() { $admin_id = session()->get('admin_id'); if($admin_id) { $result = $this->gss_model->get_new_reception_list(); // $not_booked = $this->gss_model->reception_list1(); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } else { redirect('/'); } } //Edit New reception public function edit_new_reception_details() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); // Fetch active projects, ordered alphabetically $query = $db->table('gss_new_projects') ->where('delete_status', 'ACTIVE') ->orderBy('project_name', 'ASC') ->get(); $data['projects'] = $query->getResult(); // Fetch user access details $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/edit_new_reception', $data); } public function get_new_reception_details() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $reception_id = $this->request->getPost('id'); // Use CI4's request method // Fetch reception details with project details $query = $db->table('gss_new_receptions A') ->select('A.*, B.project_name') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('A.id', $reception_id) ->get(); $result = $query->getRow(); // Fetch a single row if ($result) { return $this->response->setJSON(['result' => 1, 'message' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong.. try again"]); } } public function update_new_reception() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $reception_id = $this->request->getPost('rec_id'); $project_id = $this->request->getPost('project_id'); $booking_id = $this->request->getPost('booking_id'); $detail_id = $this->request->getPost('detail_id'); $site_number = $this->request->getPost('site_number'); $site_dimension = $this->request->getPost('site_dimension'); $customer_name = $this->request->getPost('customer_name'); $contact1 = $this->request->getPost('contact1'); $contact2 = $this->request->getPost('contact2'); $dispatched = $this->request->getPost('dispatched'); $dispatched_date = $this->request->getPost('dispatched_date'); $doc_details = $this->request->getPost('doc_details'); $ack_doc = $this->request->getPost('ack_doc'); $remarks = $this->request->getPost('remarks'); $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); $data = [ 'detail_id' => $detail_id, 'booking_id' => $booking_id, 'project_id' => $project_id, 'site_number' => $site_number, 'site_dimension' => $site_dimension, 'customer_name' => $customer_name, 'contact1' => $contact1, 'contact2' => $contact2, 'dispatched' => $dispatched, 'dispatched_date' => $dispatched_date, 'doc_details' => $doc_details, 'ack_doc' => $ack_doc, 'remarks' => $remarks, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ]; $builder = $db->table('gss_new_receptions'); $builder->where('id', $reception_id); $builder->update($data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Updated successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "You have made no changes to save"]); } } //Delete new reception public function delete_new_reception() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $reception_id = $this->request->getPost('reception_id'); $data = ['delete_status' => 'INACTIVE']; $builder = $db->table('gss_new_receptions'); $builder->where('id', $reception_id); $builder->update($data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong.. try again']); } } public function view_new_reception($reception_id=null) { $session = session(); $admin_id = $session->get('admin_id'); if ($admin_id) { $db = \Config\Database::connect(); // Fetch reception details with project details $query = $db->table('gss_new_receptions A') ->select('A.*, B.project_name') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('A.id', $reception_id) ->get(); $data['result'] = $query->getRow(); // Fetch a single row if (!$data['result']) { return view('errors/not_found'); // Load error view if no data found } // Fetch user access details $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/view_new_reception', $data); } else { return redirect()->to('/'); } } // adding controller n // Documentation projects form public function documentation_project_form() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } // Fetch active projects using Query Builder $builder = $this->db->table('gss_project_master') ->select('*') ->where('delete_status', 'ACTIVE') ->get(); // Get user type ID directly inside this function $user_type_id = $session->get('user_type_id'); // Get access details directly inside this function $access = [ 'can_edit' => true, 'can_delete' => false ]; // Modify this based on actual access logic $data = [ 'projects' => $builder->getResult(), 'user_type_id' => $user_type_id, 'access' => $access ]; return view('admin/doc_project_form', $data); } public function add_documentation_project() { $db = db_connect(); $request = service('request'); $project_name = $request->getPost('project_name'); $project_owner_name = $request->getPost('project_owner_name'); $uploadFile = function ($file, $path) { if ($file && $file->isValid() && !$file->hasMoved()) { $newName = time() . '_' . $file->getClientName(); $file->move(WRITEPATH . '../public/' . $path, $newName); return $newName; } return ''; }; $approved_plan_image = $uploadFile($request->getFile('approved_plan_image'), 'documentation_approved_uploads'); $release_order_image = $uploadFile($request->getFile('release_order_image'), 'documentation_release_uploads'); $conversion_order = $uploadFile($request->getFile('conversion_order'), 'documentation_conversion_uploads'); $brochure = $uploadFile($request->getFile('brochure'), 'documentation_brochure_uploads'); // Handling multiple file uploads for conversion_order_image $conversion_images = []; $conversion_files = $request->getFileMultiple('conversion_order_image'); if ($conversion_files) { foreach ($conversion_files as $file) { if ($file->isValid() && !$file->hasMoved()) { $filename = $uploadFile($file, 'documentation_other_uploads'); $conversion_images[] = [ 'image' => $filename, 'name' => $request->getPost('conversion_doc_name') ]; } } } $conversion_order_image = json_encode($conversion_images); $created_at = date('Y-m-d H:i:s'); $data = [ 'project_name' => $project_name, 'project_owner_name' => $project_owner_name, 'approval_image' => $approved_plan_image, 'other_image' => $conversion_order_image, 'release_image' => $release_order_image, 'conversion_order' => $conversion_order, 'brochure' => $brochure, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $db->table('gss_doc_projects')->insert($data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Project Added!']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Data could not be added']); } } public function documentation_project_list() { $session = session(); $admin_id = $session->get('admin_id'); if ($admin_id) { $db = db_connect(); $data['projects'] = $db->table('gss_project_master') ->where('delete_status', 'ACTIVE') ->get() ->getResult(); $data['user_type_id'] = session()->get('user_type_id'); $data['access'] = ['can_edit' => true, 'can_delete' => false]; // Adjust as needed return view('admin/doc_project_list', $data); } else { return redirect()->to('/'); } } public function doc_project_list() { $db = \Config\Database::connect(); $result = $db->table('gss_doc_projects') ->where('delete_status', 'ACTIVE') ->get() ->getResult(); return $this->response->setJSON($result); } public function delete_doc_project() { $db = \Config\Database::connect(); $request = service('request'); $project_table = 'gss_doc_projects'; $project_id = $request->getPost('project_id'); $data = ['delete_status' => 'INACTIVE']; $update = $db->table($project_table) ->where('id', $project_id) ->update($data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Deletion failed']); } } public function edit_doc_project() { $db = \Config\Database::connect(); $request = service('request'); $project_id = $request->getPost('project_id'); $result = $db->table('gss_doc_projects') ->where('id', $project_id) ->where('delete_status', 'ACTIVE') ->get() ->getRow(); if ($result) { return $this->response->setJSON(['project_details' => $result, 'result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } public function update_doc_project() { $db = \Config\Database::connect(); $request = service('request'); $project_id = $request->getPost('project_id'); $project_name = $request->getPost('project_name'); $project_owner_name = $request->getPost('project_owner_name'); $table = "gss_doc_projects"; $check_images = $db->table($table)->where('id', $project_id)->get()->getRow(); if (!$check_images) { return $this->response->setJSON(['result' => 0, 'message' => "Project not found"]); } // Upload files $approved_plan_image = $this->uploadFile('approved_plan_image', 'public/documentation_approved_uploads', $check_images->approval_image); $release_order_image = $this->uploadFile('release_order_image', 'public/documentation_release_uploads', $check_images->release_image); $conversion_order = $this->uploadFile('conversion_order', 'public/documentation_conversion_uploads', $check_images->conversion_order); $brochure = $this->uploadFile('brochure', 'public/documentation_brochure_uploads', $check_images->brochure); // Handling multiple file uploads for "conversion_order_image" $all_docs = json_decode($check_images->other_image, true) ?? []; $conversion_doc_name = $request->getPost('conversion_doc_name'); $uploadedFiles = []; if ($request->getFiles() && isset($_FILES['conversion_order_image'])) { foreach ($request->getFileMultiple('conversion_order_image') as $key => $file) { if ($file->isValid() && !$file->hasMoved()) { $newFileName = time() . '_' . $file->getClientName(); $file->move(WRITEPATH . 'public/documentation_other_uploads', $newFileName); $uploadedFiles[] = ['image' => $newFileName, 'name' => $conversion_doc_name[$key] ?? '']; } } } if (!empty($uploadedFiles)) { $all_docs = array_merge($all_docs, $uploadedFiles); } // Prepare update data $updatedData = [ 'project_name' => $project_name, 'project_owner_name' => $project_owner_name, 'approval_image' => $approved_plan_image, 'other_image' => json_encode($all_docs), 'release_image' => $release_order_image, 'conversion_order' => $conversion_order, 'brochure' => $brochure, 'delete_status' => 'ACTIVE', // 'updated_at' => date('Y-m-d H:i:s') ]; $db->table($table)->where('id', $project_id)->update($updatedData); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Updated Successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "No changes made"]); } } // ✅ Move uploadFile() to a private function private function uploadFile($fieldName, $folder, $default) { $file = $this->request->getFile($fieldName); if ($file && $file->isValid() && !$file->hasMoved()) { $newName = time() . '_' . $file->getClientName(); $uploadPath = WRITEPATH . 'public/' . $folder; if (!is_dir($uploadPath)) { mkdir($uploadPath, 0777, true); } if ($file->move($uploadPath, $newName)) { return $newName; } } return $default; } public function view_other_documents($id = null) { $admin_id = session()->get('admin_id'); if ($admin_id) { // Query builder without model $builder = \Config\Database::connect()->table('gss_doc_projects'); $builder->where([ 'delete_status' => 'ACTIVE', 'id' => $id ]); $query = $builder->get(); $data['projects'] = $query->getRow(); // assuming these functions exist $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/view_other_digidocuments', $data); } else { return redirect()->to('/'); } } public function get_assigned_accessed_rigts() { $db = \Config\Database::connect(); $department_id = $this->request->getPost('department_id'); $menu_id = $this->request->getPost('menu_id'); $result = $db->table('gss_access_controls') ->where(['delete_status' => 'ACTIVE', 'department_id' => $department_id]) ->get() ->getRow(); if ($result) { $access_menu_ids = unserialize($result->menu_id); $delete_id = unserialize($result->delete_id); $preview_id = unserialize($result->preview_id); $edit_id = unserialize($result->edit_id); if ($access_menu_ids) { return $this->response->setJSON([ 'access_result' => 1, 'menu_id' => $menu_id, 'menu_ids' => $access_menu_ids, 'delete_id' => $delete_id, 'preview_id' => $preview_id, 'edit_id' => $edit_id, 'result' => 1 ]); } } return $this->response->setJSON(['result' => 0]); } public function delete_other_document() { $db = \Config\Database::connect(); $request = service('request'); $pr_id = $request->getPost('pr_id'); $file_link = $request->getPost('file_link'); $file_name = $request->getPost('file_name'); $table = "gss_doc_projects"; // Fetch existing document record $check_images = $db->table($table) ->where('id', $pr_id) ->get() ->getRow(); $array = []; if ($check_images) { if (!empty($check_images->other_image)) { $prev_con_docs = json_decode($check_images->other_image); foreach ($prev_con_docs as $val) { if ($val->image != $file_link && $val->name != $file_name) { $data['image'] = $val->image; $data['name'] = $val->name; $array[] = $data; } } } $all_docs = json_encode($array); // Update database $update = $db->table($table) ->where('id', $pr_id) ->update(['other_image' => $all_docs]); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Deleted Successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Could not delete.. try again"]); } } else { return $this->response->setJSON(['result' => 0, 'message' => "No data found"]); } } public function close_document_project() { $db = \Config\Database::connect(); $request = service('request'); $table = 'gss_doc_projects'; $project_id = $request->getPost('project_id'); // Check current project status $check_status = $db->table($table)->where('id', $project_id)->get()->getRow(); if (!$check_status) { return $this->response->setJSON(['result' => 0, 'message' => 'Project not found']); } // Toggle status $new_status = ($check_status->project_status === 'ONGOING') ? 'COMPLETED' : 'ONGOING'; $db->table($table)->where('id', $project_id)->update(['project_status' => $new_status]); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Changed successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No changes made']); } } public function documentation_site_form() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $table = "gss_doc_projects"; $where = ['delete_status' => 'ACTIVE']; $data['projects'] = $db->table($table)->where($where)->get()->getResult(); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/doc_site_form', $data); } public function add_documentation_site() { $db = \Config\Database::connect(); $request = \Config\Services::request(); $project_id = $request->getPost('project_id'); $site_number = $request->getPost('site_number'); $dimension = $request->getPost('dimension'); $created_at = date('Y-m-d H:i:s'); // Using standard timestamp format $table = "gss_doc_sites"; // Check if the site already exists $existingSite = $db->table($table) ->where(['site_number' => $site_number, 'project_id' => $project_id, 'delete_status' => 'ACTIVE']) ->get() ->getRow(); if ($existingSite) { return $this->response->setJSON(['result' => 0, 'message' => "Site already exists"]); } // Insert new site $data = [ 'project_id' => $project_id, 'site_number' => $site_number, 'dimension' => $dimension, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $result = $db->table($table)->insert($data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Site Added!"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Data could not be added"]); } } public function documentation_site_list() { $session = session(); if (!$session->has('admin_id')) { return redirect()->to('/'); } $db = \Config\Database::connect(); $table = "gss_doc_projects"; $where = ['delete_status' => 'ACTIVE']; $data['projects'] = $db->table($table) ->where($where) ->get() ->getResult(); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/doc_site_list', $data); } public function doc_site_list() { $db = \Config\Database::connect(); $builder = $db->table('gss_doc_sites A'); $builder->select('A.*, B.id as project_id, B.project_name'); $builder->join('gss_doc_projects B', 'B.id = A.project_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $result = $builder->get()->getResult(); return $this->response->setJSON($result); } public function delete_doc_site() { $db = \Config\Database::connect(); $site_id = $this->request->getPost('site_id'); $builder = $db->table('gss_doc_sites'); $builder->where('id', $site_id); $builder->update(['delete_status' => 'INACTIVE']); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to delete']); } } public function edit_doc_site() { $db = \Config\Database::connect(); $id = $this->request->getPost('id'); $builder = $db->table('gss_doc_sites A'); $builder->select('A.*, B.id as project_id, B.project_name'); $builder->join('gss_doc_projects B', 'B.id = A.project_id'); $builder->where('A.id', $id); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $result = $builder->get()->getRow(); if ($result) { return $this->response->setJSON(['site_details' => $result, 'result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } public function update_doc_site() { $db = \Config\Database::connect(); $site_id = $this->request->getPost('site_id'); $project_id = $this->request->getPost('project_id'); $site_number = $this->request->getPost('site_number'); $dimension = $this->request->getPost('dimension'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('d-m-Y'); $table = "gss_doc_sites"; // Fetch existing site data $builder = $db->table($table); $site_data = $builder->where('id', $site_id)->where('delete_status', 'ACTIVE')->get()->getRow(); if (!$site_data) { return $this->response->setJSON(['result' => 0, 'message' => 'Site not found']); } // Check if the site number already exists in the project (excluding current site) $existing_sites = $builder ->select('site_number') ->where('delete_status', 'ACTIVE') ->where('project_id', $project_id) ->where('site_number !=', $site_data->site_number) ->get() ->getResultArray(); $existing_site_numbers = array_column($existing_sites, 'site_number'); if (in_array($site_number, $existing_site_numbers)) { return $this->response->setJSON(['result' => 2, 'message' => "Site number already exists in this project"]); } // Update site data $builder->where('id', $site_id)->where('project_id', $project_id)->update([ 'site_number' => $site_number, 'dimension' => $dimension ]); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Updated successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Failed to update. Try again"]); } } public function owner_document_form() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $builder = $db->table("gss_doc_projects"); $data['projects'] = $builder->where('delete_status', 'ACTIVE')->get()->getResult(); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/doc_owner_form', $data); } public function get_doc_projects() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $project_id = $this->request->getPost('project_id'); if (!$project_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid project ID']); } $db = \Config\Database::connect(); $builder = $db->table('gss_doc_sites'); $builder->select('*') ->where(['project_id' => $project_id, 'delete_status' => 'ACTIVE']) ->orderBy("ABS(site_number)", "ASC"); $sites = $builder->get()->getResult(); if ($sites) { return $this->response->setJSON(['result' => 1, 'sites' => $sites]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No sites found']); } } public function add_owner_documents() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } helper(['form', 'url']); $project_id = $this->request->getPost('project_id'); $site_number = $this->request->getPost('site_number'); $owner_name = $this->request->getPost('owner_name'); // Function to handle file upload function uploadFile($request_name, $folder, $request) { $file = $request->getFile($request_name); if (!$file || !$file->isValid() || $file->hasMoved()) { return ''; } $newName = preg_replace('/\s+/', '_', $file->getName()); $file->move($folder, $newName); return $newName; } // Single file uploads $sales_agreement_files = uploadFile('sales_agreement_files', 'public/doc_sales_agreement', $this->request); $sales_deed = uploadFile('sales_deed', 'public/doc_sales_deed', $this->request); $owner_khata = uploadFile('owner_khata', 'public/doc_owner_khata', $this->request); // Multiple file uploads - EC documents $ec = []; $ec_from_dates = $this->request->getPost('ec_from_date'); $ec_to_dates = $this->request->getPost('ec_to_date'); $ec_uploads = $this->request->getFileMultiple('ec_uploads'); if (!empty($ec_from_dates)) { foreach ($ec_from_dates as $index => $from_date) { $file_name = isset($ec_uploads[$index]) ? uploadFile("ec_uploads[$index]", 'public/doc_ec_uploads', $this->request) : ''; if (!empty($from_date)) { $ec[] = [ 'id' => $index + 1, 'ec_from' => $from_date, 'ec_to' => $ec_to_dates[$index] ?? '', 'ec_upload' => $file_name ]; } } } $ec = json_encode($ec); // Multiple file uploads - Owner Tax documents $owner = []; $owner_from_dates = $this->request->getPost('owner_from_date'); $owner_to_dates = $this->request->getPost('owner_to_date'); $owner_tax_uploads = $this->request->getFileMultiple('owner_tax'); if (!empty($owner_from_dates)) { foreach ($owner_from_dates as $index => $from_date) { $file_name = isset($owner_tax_uploads[$index]) ? uploadFile("owner_tax[$index]", 'public/doc_owner_tax_uploads', $this->request) : ''; if (!empty($from_date)) { $owner[] = [ 'id' => $index + 1, 'owner_from' => $from_date, 'owner_to' => $owner_to_dates[$index] ?? '', 'tax_upload' => $file_name ]; } } } $owner = json_encode($owner); // Multiple file uploads - Other Owner Documents $upload_doc = []; $doc_names = $this->request->getPost('documents_name'); $doc_files = $this->request->getFileMultiple('documents'); if (!empty($doc_names)) { foreach ($doc_names as $index => $name) { $file_name = isset($doc_files[$index]) ? uploadFile("documents[$index]", 'public/doc_owner_documents', $this->request) : ''; if (!empty($name)) { $upload_doc[] = [ 'id' => $index + 1, 'doc_name' => $name, 'upload_doc' => $file_name ]; } } } $upload_doc = json_encode($upload_doc); // Get current timestamp $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('d-m-Y'); // Data to insert $data = [ 'project_id' => $project_id, 'site_number' => $site_number, 'owner_name' => $owner_name, 'sales_agreement_files' => $sales_agreement_files, 'sales_deed' => $sales_deed, 'ec' => $ec, 'owner' => $owner, 'owner_khata' => $owner_khata, 'upload_doc' => $upload_doc, 'created_at' => $created_at ]; // Insert data into DB $db = \Config\Database::connect(); $builder = $db->table('gss_doc_owner_documents'); $insert = $builder->insert($data); return $this->response->setJSON([ 'result' => $insert ? 1 : 0, 'message' => $insert ? "Added successfully!" : "File could not be added" ]); } public function owner_document_list() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); // Fetch projects $db = \Config\Database::connect(); $builder = $db->table('gss_doc_projects'); $builder->select('*')->where('delete_status', 'ACTIVE')->orderBy('project_name', 'ASC'); $data['projects'] = $builder->get()->getResult(); return view('admin/doc_owner_document_list', $data); } public function get_document_projects() { $project_status = $this->request->getPost('project_status'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_projects'); // Apply filters if ($project_status !== "ALL") { $builder->where('project_status', $project_status); } $builder->where('delete_status', 'ACTIVE')->orderBy('project_name', 'ASC'); // Fetch results $query = $builder->get()->getResult(); if (!empty($query)) { return $this->response->setJSON(['result' => 1, 'message' => $query]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No Data Found']); } } public function get_doc_owner_documents_list() { $db = \Config\Database::connect(); $project = $this->request->getGet('project'); $project_status = $this->request->getGet('project_status'); $builder = $db->table('gss_doc_owner_documents A') ->select('A.*, B.id as project_id, B.project_name') ->join('gss_doc_projects B', 'B.id = A.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE'); if ($project != 0) { $builder->where('A.project_id', $project); } if ($project_status !== "ALL") { $builder->where('B.project_status', $project_status); } $builder->orderBy('A.id', 'DESC'); $query = $builder->get()->getResult(); $result = []; foreach ($query as $row) { $result[] = [ 'id' => $row->id, 'project_id' => $row->project_id, 'site_number' => $row->site_number, 'owner_name' => $row->owner_name, 'sales_agreement_files' => $row->sales_agreement_files, 'sales_deed' => $row->sales_deed, 'ec' => $row->ec, 'owner' => $row->owner, 'upload_doc' => $row->upload_doc, 'owner_khata' => $row->owner_khata, 'project_name' => $row->project_name ]; } return $this->response->setJSON($result); } public function view_owner_khata() { $db = \Config\Database::connect(); $uri = service('uri'); $id = $uri->getSegment(2); $query = $db->table('gss_doc_owner_documents') ->select('*') ->where('id', $id) ->get() ->getRow(); if (!$query) { return redirect()->to('/')->with('error', 'Record not found'); } $data['details'] = $query; $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/view_owner_khata', $data); } public function view_owner_sales_deeds() { $db = \Config\Database::connect(); $uri = service('uri'); $id = $uri->getSegment(2); $query = $db->table('gss_doc_owner_documents') ->select('*') ->where('id', $id) ->get() ->getRow(); if (!$query) { return redirect()->to('/')->with('error', 'Record not found'); } $data['details'] = $query; $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/view_owner_sales_deeds', $data); } public function view_owner_sales_agreement() { $db = \Config\Database::connect(); $uri = service('uri'); $id = $uri->getSegment(2); $query = $db->table('gss_doc_owner_documents') ->select('*') ->where('id', $id) ->get() ->getRow(); if (!$query) { return redirect()->to('/')->with('error', 'Record not found'); } $data['details'] = $query; $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/view_owner_sales_agreement', $data); } public function view_owner_ec_documents() { $db = \Config\Database::connect(); $uri = service('uri'); $id = $uri->getSegment(2); $query = $db->table('gss_doc_owner_documents') ->select('*') ->where('id', $id) ->get() ->getRow(); if (!$query) { return redirect()->to('/')->with('error', 'Record not found'); } $data['details'] = $query; $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/view_owner_documents', $data); } public function get_ec_selected() { $id = $this->request->getPost('id'); $ec_id = $this->request->getPost('ec_id'); // This should be an array // Get the row from gss_doc_owner_documents $builder = $this->db->table('gss_doc_owner_documents'); $builder->where('id', $id); $check = $builder->get()->getRow(); if (!$check) { return $this->response->setJSON(['result' => 0, 'error' => 'Document not found']); } $get_ec = $check->ec; $ec = json_decode($get_ec); $ec_array = []; foreach ($ec_id as $owner_ec_id) { foreach ($ec as $entry) { if ($entry->id == $owner_ec_id) { $ec_array[] = $entry->ec_upload; break; } } } $ec_docs = json_encode($ec_array); // Check if a row already exists in gss_owner_tax_docs $taxDocTable = $this->db->table('gss_owner_tax_docs'); $taxDocTable->where('owner_doc_id', $id); $existing = $taxDocTable->get()->getRow(); if ($existing) { // Delete the existing record $taxDocTable->where('owner_doc_id', $id)->delete(); } // Insert the new record $insertData = [ 'owner_doc_id' => $id, 'document' => $ec_docs ]; $result = $this->db->table('gss_owner_tax_docs')->insert($insertData); if ($result) { return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } public function send_mail_owner_tax() { $admin_id = session()->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } // Get ID from URI segment $uri=service('uri'); $id = $uri->getSegment(2); // same as uri->segment(2) in CI3 // Fetch owner document details $builder = $this->db->table('gss_doc_owner_documents'); $builder->where('id', $id); $details = $builder->get()->getRow(); if (!$details) { return redirect()->to('/')->with('error', 'Document not found'); } // Fetch tax docs $docs = $this->db->table('gss_owner_tax_docs') ->where('owner_doc_id', $id) ->get()->getRow(); // Fetch project info $project = $this->db->table('gss_doc_projects') ->where('id', $details->project_id) ->get()->getRow(); // Fetch user info $user = $this->db->table('gss_login') ->where('user_id', $admin_id) ->get()->getRow(); // Access control logic (assuming you still have access_id and access_details methods) $data = [ 'details' => $details, 'docs' => $docs, 'project' => $project, 'user' => $user, 'user_type_id' => $this->access_id(), // still uses existing method 'access' => $this->access_details(), // still uses existing method ]; return view('admin/send_owner_mail', $data); } public function add_owner_doc_tax() { $admin_id = session()->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $from = $this->request->getPost('from'); $to = $this->request->getPost('to'); $subject = $this->request->getPost('subject'); $message = $this->request->getPost('message'); $document = $this->request->getPost('documents'); $file_type = $this->request->getPost('file_type'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('d-m-Y'); // Insert into gss_owner_mail_khata $insertData = [ 'email_from' => $from, 'email_to' => $to, 'subject' => $subject, 'message' => $message, 'document' => json_encode($document), 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ]; $this->db->table('gss_owner_mail_khata')->insert($insertData); $insertId = $this->db->insertID(); if (!$insertId) { return $this->response->setJSON(['result' => 0, 'message' => 'DB insert failed']); } // Get inserted mail record $details = $this->db->table('gss_owner_mail_khata') ->where('id', $insertId) ->get()->getRow(); $documents = json_decode($details->document); $attachments = []; foreach ($documents as $doc) { if ($file_type === 'owt') { $path = FCPATH . 'public/doc_owner_tax_uploads/' . $doc; } elseif ($file_type === 'owe') { $path = FCPATH . 'public/doc_ec_uploads/' . $doc; } elseif ($file_type === 'od') { $path = FCPATH . 'public/doc_owner_documents/' . $doc; } $attachments[] = $path; } // Get sender signature and cc $user = $this->db->table('gss_login') ->where('user_id', $admin_id) ->get()->getRow(); $sign = $user->signature; $cc = $user->email; // Prepare email body $base_url = base_url(); $message .= '<br><br>Thanks and regards,<br><br>'; $message .= "<img src='" . $base_url . "public/assets/images/gss_logo.jpg' style='width:20%'><br>"; $message .= $sign; // Load email configuration $email = \Config\Services::email(); $config = [ 'protocol' => 'smtp', 'SMTPHost' => 'ssl://smtp.googlemail.com', 'SMTPPort' => 465, 'SMTPUser' => 'gssorganised@gmail.com', 'SMTPPass' => 'GSSKarthi@1236#', 'mailType' => 'html', 'charset' => 'utf-8', 'newline' => "\r\n", ]; $email->initialize($config); // Compose and send $email->setFrom($from, 'GSS'); $email->setTo($to); $email->setCC($cc); $email->setSubject($subject); $email->setMessage($message); foreach ($attachments as $filePath) { if (file_exists($filePath)) { $email->attach($filePath); } } if ($email->send()) { return $this->response->setJSON(['result' => 1, 'message' => 'Your Email has successfully been sent.']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Email failed to send.']); } } public function delete_owner_ec() { $id = $this->request->getPost('id'); $ec_id = $this->request->getPost('ec_id'); // Fetch the row from the table $builder = $this->db->table('gss_doc_owner_documents'); $builder->where('id', $id); $get_ec = $builder->get()->getRow(); if (!$get_ec || empty($get_ec->ec)) { return $this->response->setJSON(['result' => 0, 'message' => 'EC data not found.']); } $ec = json_decode($get_ec->ec); $updated_ec = []; foreach ($ec as $key => $ec_det) { if ($ec_det->id == $ec_id) { // If there's only one item in the array, clear everything if (count($ec) == 1) { $updated_ec = []; break; } // Else, skip this item to "delete" it continue; } $updated_ec[] = $ec_det; } $encoded = !empty($updated_ec) ? json_encode($updated_ec) : ''; // Update the record $updateData = ['ec' => $encoded]; $update = $this->db->table('gss_doc_owner_documents') ->where('id', $id) ->update($updateData); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No changes made.']); } } public function view_owner_tax_documents() { $db = \Config\Database::connect(); $uri = service('uri'); $id = $uri->getSegment(2); $query = $db->table('gss_doc_owner_documents') ->select('*') ->where('id', $id) ->get() ->getRow(); if (!$query) { return redirect()->to('/')->with('error', 'Record not found'); } $data['details'] = $query; $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/view_owner_tax_documents', $data); } public function get_tax_selected() { $admin_id = session()->get('admin_id'); if ($admin_id) { $id = $this->request->getPost('id'); $selected_tax = $this->request->getPost('selected_tax'); // 1. Get tax data from gss_doc_owner_documents $builder = \Config\Database::connect()->table('gss_doc_owner_documents'); $check = $builder->where('id', $id)->get()->getRow(); if (!$check) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid ID']); } $tax = json_decode($check->owner); $owner_array = []; foreach ($selected_tax as $ot) { foreach ($tax as $get_tax_id) { if ($get_tax_id->id == $ot) { $owner_array[] = $get_tax_id->tax_upload; } } } $owner_docs = json_encode($owner_array); // 2. Check if a row already exists in gss_owner_tax_docs $taxDocTable = \Config\Database::connect()->table('gss_owner_tax_docs'); $existing = $taxDocTable->where('owner_doc_id', $id)->get()->getRow(); if ($existing) { // Delete existing row $taxDocTable->where('owner_doc_id', $id)->delete(); } // 3. Insert new row $insertData = [ 'owner_doc_id' => $id, 'document' => $owner_docs ]; $result = $taxDocTable->insert($insertData); if ($result) { return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } else { return redirect()->to('/'); } } public function delete_owner_tax() { $id = $this->request->getPost('id'); $tax_id = $this->request->getPost('tax_id'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_owner_documents'); // 1. Fetch the owner document row $get_owner = $builder->where('id', $id)->get()->getRow(); if (!$get_owner) { return $this->response->setJSON(['result' => 0, 'message' => 'Record not found']); } $owner_data = json_decode($get_owner->owner); $new_array = []; foreach ($owner_data as $key => $owner_det) { if ($owner_det->id != $tax_id) { $new_array[] = $owner_det; } } $encoded = !empty($new_array) ? json_encode($new_array) : ''; // 2. Update the row with modified owner data $update_result = $builder->where('id', $id)->update(['owner' => $encoded]); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Nothing was deleted.']); } } public function view_owner_documents() { $db = \Config\Database::connect(); $uri = service('uri'); $id = $uri->getSegment(2); // Fetch document details $query = $db->table('gss_doc_owner_documents') ->select('*') ->where('id', $id) ->get() ->getRow(); if (!$query) { return redirect()->to('/')->with('error', 'Record not found'); } // Fetch user access details $data = [ 'details' => $query, 'user_type_id' => $this->access_id(), 'access' => $this->access_details(), ]; return view('admin/view_owner_docs', $data); } public function get_doc_selected() { $id = $this->request->getPost('id'); $ec_id = $this->request->getPost('ec_id'); // array of selected ec ids $db = \Config\Database::connect(); // Step 1: Get document record $builder = $db->table('gss_doc_owner_documents'); $check = $builder->where('id', $id)->get()->getRow(); if (!$check) { return $this->response->setJSON(['result' => 0, 'message' => 'Record not found']); } $client_doc = json_decode($check->upload_doc); $ec_array = []; // Step 2: Find selected EC documents foreach ($ec_id as $ec_selected_id) { foreach ($client_doc as $doc) { if ($doc->id == $ec_selected_id) { $ec_array[] = $doc->upload_doc; } } } $ec_docs = json_encode($ec_array); // Step 3: Insert/Update into gss_owner_tax_docs $builder = $db->table('gss_owner_tax_docs'); $existing = $builder->where('owner_doc_id', $id)->get()->getRow(); if ($existing) { $builder->where('owner_doc_id', $id)->delete(); } $insert_data = [ 'owner_doc_id' => $id, 'document' => $ec_docs ]; $result = $builder->insert($insert_data); if ($result) { return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } public function delete_owner_doc() { $id = $this->request->getPost('id'); $doc_id = $this->request->getPost('doc_id'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_owner_documents'); $get_doc = $builder->where('id', $id)->get()->getRow(); if (!$get_doc) { return $this->response->setJSON(['result' => 0, 'message' => 'Record not found']); } $doc_list = json_decode($get_doc->upload_doc); $updated_docs = []; foreach ($doc_list as $doc_item) { if ($doc_item->id != $doc_id) { $updated_docs[] = $doc_item; } } $encoded = !empty($updated_docs) ? json_encode($updated_docs) : ''; $update_result = $builder->where('id', $id)->update(['upload_doc' => $encoded]); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0]); } } public function edit_owner_documents() { $db = \Config\Database::connect(); $uri = service('uri'); $id = $uri->getSegment(2); // Fetch document details $documentQuery = $db->table('gss_doc_owner_documents') ->select('*') ->where('id', $id) ->get() ->getRow(); if (!$documentQuery) { return redirect()->to('/')->with('error', 'Document not found'); } // Fetch active projects $projectsQuery = $db->table('gss_doc_projects') ->select('*') ->where('delete_status', 'ACTIVE') ->orderBy('project_name', 'ASC') ->get() ->getResult(); // Prepare data for view $data = [ 'details' => $documentQuery, 'projects' => $projectsQuery, 'user_type_id' => $this->access_id(), 'access' => $this->access_details(), ]; return view('admin/edit_owner_document', $data); } public function update_owner_documents() { if (!session('admin_id')) { return redirect('/'); } $id = $this->request->getPost('id'); $project_id = $this->request->getPost('project_id'); $site_number = $this->request->getPost('site_number'); $owner_name = $this->request->getPost('owner_name'); if (empty($id)) { return $this->response->setJSON(['result' => 0, 'message' => "Invalid request!"]); } $table = 'gss_doc_owner_documents'; $db = \Config\Database::connect(); // Fetch existing record $query = $db->table($table)->where('id', $id)->get(); $det = $query->getRow(); if (!$det) { return $this->response->setJSON(['result' => 0, 'message' => "Record not found!"]); } // Function to handle file upload and resizing function process_upload($field_name, $folder, $existing_file) { $file = \Config\Services::request()->getFile($field_name); if ($file && $file->isValid() && !$file->hasMoved()) { $newName = preg_replace('/\s+/', '_', $file->getRandomName()); $upload_path = 'public/' . $folder; if (!is_dir($upload_path)) { mkdir($upload_path, 0777, true); } if ($file->move($upload_path, $newName)) { // Resize image $image = \Config\Services::image() ->withFile($upload_path . $newName) ->resize(900, 900, true, 'auto') ->save($upload_path . $newName); return 'public/' . $folder . $newName; // Return file path for database } } return $existing_file; // Return existing file if no new file is uploaded } // Process file uploads $sales_agreement_files = process_upload('sales_agreement_files', 'doc_sales_agreement/', $det->sales_agreement_files); $sales_deed = process_upload('sales_deed', 'doc_sales_deed/', $det->sales_deed); // Update database $modified_at = date('d-m-Y'); $data = [ 'project_id' => $project_id, 'site_number' => $site_number, 'owner_name' => $owner_name, 'sales_agreement_files' => $sales_agreement_files, 'sales_deed' => $sales_deed, 'modified_at' => $modified_at ]; $db->table($table)->where('id', $id)->update($data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Updated!"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "No changes added"]); } } public function delete_doc_owner_documents() { $db = \Config\Database::connect(); // CI4 database connection $table = 'gss_doc_owner_documents'; $id = $this->request->getPost('id'); if (!$id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid request!']); } $data = ['delete_status' => 'INACTIVE']; $db->table($table)->where('id', $id)->update($data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No changes made or record not found']); } } public function send_mail_owner_contents() { $admin_id = session()->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $request = \Config\Services::request(); $id = $request->uri->getSegment(2); // Get ID from URI if (!$id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid request!']); } // Fetch document owner details $details = $db->table('gss_doc_owner_documents')->where('id', $id)->get()->getRow(); if (!$details) { return $this->response->setJSON(['result' => 0, 'message' => 'Document not found!']); } // Fetch project details $project = $db->table('gss_doc_projects')->where('id', $details->project_id)->get()->getRow(); // Fetch user details $user = $db->table('gss_login')->where('user_id', $admin_id)->get()->getRow(); // Load data into the view return view('admin/send_mail_contents', [ 'details' => $details, 'project' => $project, 'user' => $user, 'user_type_id' => $this->access_id(), 'access' => $this->access_details() ]); } public function delete_owner_khata() { $db = \Config\Database::connect(); $request = \Config\Services::request(); $id = $request->getPost('id'); if (!$id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid request!']); } $table = "gss_doc_owner_documents"; // Update the database $db->table($table)->where('id', $id)->update(['owner_khata' => '']); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No changes made!']); } } public function delete_owner_sales_agreement() { $id = $this->request->getPost('id'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_owner_documents'); // Update the sales_agreement_files column to empty $updateResult = $builder->where('id', $id)->update(['sales_agreement_files' => '']); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Nothing was deleted.']); } } public function delete_owner_sales_deed() { $id = $this->request->getPost('id'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_owner_documents'); $updateData = ['sales_deed' => '']; $builder->where('id', $id)->update($updateData); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Nothing was deleted.']); } } // Client public function client_document_form() { $session = session(); $admin_id = $session->get('admin_id'); if ($admin_id) { $db = \Config\Database::connect(); $table = "gss_doc_projects"; $where = ['delete_status' => 'ACTIVE']; $order_by = "project_name"; // Fetch data directly inside the controller (without using a model) $data['projects'] = $db->table($table) ->where($where) ->orderBy($order_by, "ASC") ->get() ->getResult(); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/client_doc_form', $data); } else { return redirect()->to('/'); } } public function add_client_documents() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $project_id = $this->request->getPost('project_id'); $site_number = $this->request->getPost('site_number'); $client_name = $this->request->getPost('client_name'); // File Upload Functionality $uploadPaths = [ 'booking_application' => 'public/doc_client_booking_applications', 'sales_agreement_files' => 'public/doc_client_sales_agreement', 'sales_deed' => 'public/doc_client_sales_deed', 'client_khata' => 'public/doc_client_khata' ]; $uploadedFiles = []; foreach ($uploadPaths as $requestName => $path) { $file = $this->request->getFile($requestName); if ($file && $file->isValid() && !$file->hasMoved()) { $newName = $file->getRandomName(); $file->move($path, $newName); $uploadedFiles[$requestName] = $newName; } else { $uploadedFiles[$requestName] = ""; } } // Handling Multiple File Uploads (EC, Tax, and Documents) $multiUploads = [ 'ec' => [ 'request' => 'ec_uploads', 'path' => 'public/doc_client_ec_uploads', 'fromDate' => $this->request->getPost('ec_from_date'), 'toDate' => $this->request->getPost('ec_to_date') ], 'client' => [ 'request' => 'client_tax', 'path' => 'public/doc_client_tax_uploads', 'fromDate' => $this->request->getPost('client_from_date'), 'toDate' => $this->request->getPost('client_to_date'), 'paidDate' => $this->request->getPost('paid_date') ], 'upload_doc' => [ 'request' => 'documents', 'path' => 'public/doc_client_documents', 'docName' => $this->request->getPost('documents_name') ] ]; $multiFileResults = []; foreach ($multiUploads as $key => $details) { $files = $this->request->getFileMultiple($details['request']); $uploads = []; foreach ($files as $index => $file) { if ($file->isValid() && !$file->hasMoved()) { $newName = $file->getRandomName(); $file->move($details['path'], $newName); $uploadData = [ 'id' => $index + 1, 'from_date' => $details['fromDate'][$index] ?? '', 'to_date' => $details['toDate'][$index] ?? '', 'upload' => $newName ]; if (isset($details['paidDate'])) { $uploadData['paid_date'] = $details['paidDate'][$index] ?? ''; } if (isset($details['docName'])) { $uploadData['doc_name'] = $details['docName'][$index] ?? ''; } $uploads[] = $uploadData; } } $multiFileResults[$key] = !empty($uploads) ? json_encode($uploads) : ""; } $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('d-m-Y'); $data = [ 'project_id' => $project_id, 'site_number' => $site_number, 'client_name' => $client_name, 'booking_application' => $uploadedFiles['booking_application'], 'sales_agreement_files' => $uploadedFiles['sales_agreement_files'], 'sales_deed' => $uploadedFiles['sales_deed'], 'ec' => $multiFileResults['ec'], 'client' => $multiFileResults['client'], 'client_khata' => $uploadedFiles['client_khata'], 'upload_doc' => $multiFileResults['upload_doc'], 'created_at' => $created_at ]; $result = $db->table('gss_doc_client_documents')->insert($data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => "Added!"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Data could not be added"]); } } public function client_document_list() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); $data['projects'] = $db->table('gss_doc_projects') ->where('delete_status', 'ACTIVE') ->orderBy('project_name', 'ASC') ->get() ->getResult(); return view('admin/doc_client_document_list', $data); } public function get_doc_client_documents_list() { $project = $this->request->getGet('project'); $project_status = $this->request->getGet('project_status'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_client_documents A'); $builder->select('A.*, B.id as project_id, B.project_name'); $builder->join('gss_doc_projects B', 'B.id = A.project_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); if (!empty($project) && $project !== 'undefined') { $builder->where('A.project_id', $project); } if (!empty($project_status) && strtoupper($project_status) !== "ALL") { $builder->where('B.project_status', $project_status); } $builder->orderBy('A.id', 'DESC'); $query = $builder->get(); $res = $query->getResult(); if (empty($res)) { return $this->response->setJSON(['result' => 0, 'message' => 'No data found']); } $array = []; foreach ($res as $result) { $array[] = [ 'id' => $result->id, 'project_id' => $result->project_id, 'site_number' => $result->site_number, 'client_name' => $result->client_name, 'booking_application' => $result->booking_application, 'sales_agreement_files' => $result->sales_agreement_files, 'sales_deed' => $result->sales_deed, 'ec' => $result->ec, 'client' => $result->client, 'upload_doc' => $result->upload_doc, 'client_khata' => $result->client_khata, 'project_name' => $result->project_name ]; } return $this->response->setJSON($array); } public function view_client_booking_application() { // Get the database connection $db = \Config\Database::connect(); // Get the 'id' from the URI segment $uri = service('uri'); $id = $uri->getSegment(2); // For CodeIgniter 4, use $this->request->uri->getSegment() instead of $this->uri->segment() // Define the table and condition for fetching data $table = "gss_doc_client_documents"; $where = ['id' => $id]; // Query to get the details $builder = $db->table($table); $builder->where($where); $query = $builder->get(); // Fetch the first row $data['details'] = $query->getRow(); // Fetch user type ID and access details from session (assuming you have them stored in the session) $data['user_type_id'] = session()->get('user_type_id'); $data['access'] = session()->get('access_details'); // Load the view and pass the data return view('admin/view_client_booking_application', $data); } public function delete_client_booking() { $request = service('request'); $id = $request->getPost('id'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_client_documents'); $builder->where('id', $id); $builder->update(['booking_application' => '']); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0]); } } public function view_client_sales_agreement() { // Get the database connection $db = \Config\Database::connect(); // Get the ID from the URL segment $uri = service('uri'); $id = $uri->getSegment(2); // Query the 'gss_doc_client_documents' table to get the document details by 'id' $builder = $db->table('gss_doc_client_documents'); $builder->where('id', $id); $query = $builder->get(); $data['details'] = $query->getRow(); // Get user type and access details from session $data['user_type_id'] = session()->get('user_type_id'); $data['access'] = session()->get('access_details'); // Load the view with the data return view('admin/view_client_sales_agreement', $data); } public function view_client_sales_deeds() { // Get the database connection $db = \Config\Database::connect(); // Get the ID from the URL segment $uri = service('uri'); $id = $uri->getSegment(2); // Query the 'gss_doc_client_documents' table to get the document details by 'id' $builder = $db->table('gss_doc_client_documents'); $builder->where('id', $id); $query = $builder->get(); $data['details'] = $query->getRow(); // Get user type and access details from session $data['user_type_id'] = session()->get('user_type_id'); $data['access'] = session()->get('access_details'); // Load the view with the data return view('admin/view_client_sales_deed', $data); } public function view_client_khata() { // Get the database connection $db = \Config\Database::connect(); // Get the ID from the URL segment $uri = service('uri'); $id = $uri->getSegment(2); // Query the 'gss_doc_client_documents' table to get the document details by 'id' $builder = $db->table('gss_doc_client_documents'); $builder->where('id', $id); $query = $builder->get(); $data['details'] = $query->getRow(); // Get user type and access details from session $data['user_type_id'] = session()->get('user_type_id'); $data['access'] = session()->get('access_details'); // Load the view with the data return view('admin/view_client_khata', $data); } public function view_client_ec_documents() { $uri = service('uri'); $id = $uri->getSegment(2); if (!$id) { return redirect()->to('/'); } $table = 'gss_doc_client_documents'; $db = \Config\Database::connect(); $details = $db->table($table)->where('id', $id)->get()->getRow(); if (!$details) { return redirect()->to('/'); } $user_type_id = session()->get('user_type_id'); $access = session()->get('access_details'); $data = [ 'details' => $details, 'user_type_id' => $user_type_id, 'access' => $access ]; return view('admin/view_client_ec_documents', $data); } public function get_client_ec_selected() { $id = $this->request->getPost('id'); $ec_id = $this->request->getPost('ec_id'); // Get client document row $db = \Config\Database::connect(); $builder = $db->table('gss_doc_client_documents'); $builder->where(['id' => $id]); $check = $builder->get()->getRow(); if (!$check) { return $this->response->setJSON(['result' => 0, 'error' => 'Client document not found']); } $ec_array = []; $ec = json_decode($check->ec); foreach ($ec_id as $owner_ec) { foreach ($ec as $get_ec_id) { if ($get_ec_id->id == $owner_ec) { $ec_array[] = $get_ec_id->ec_upload; } } } $ec_docs = json_encode($ec_array); // Check if row already exists $builder = $db->table('gss_client_tax_docs'); $builder->where(['client_doc_id' => $id]); $check_row = $builder->get()->getRow(); if ($check_row) { // Delete existing $builder->where(['client_doc_id' => $id]); $builder->delete(); } // Insert new row $insertData = [ 'client_doc_id' => $id, 'document' => $ec_docs ]; $insert = $db->table('gss_client_tax_docs')->insert($insertData); if ($insert) { return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } public function send_mail_client_tax() { $admin_id = session()->get('admin_id'); if ($admin_id) { $uri = service('uri'); $id = $uri->getSegment(2); $db = \Config\Database::connect(); // Fetch client document details $builder = $db->table('gss_doc_client_documents'); $builder->where(['id' => $id]); $data['details'] = $details = $builder->get()->getRow(); // Fetch client tax docs $builder = $db->table('gss_client_tax_docs'); $builder->where(['client_doc_id' => $id]); $data['docs'] = $builder->get()->getRow(); // Fetch project details $builder = $db->table('gss_doc_projects'); $builder->where(['id' => $details->project_id]); $data['project'] = $builder->get()->getRow(); // Fetch user details $builder = $db->table('gss_login'); $builder->where(['user_id' => $admin_id]); $data['user'] = $builder->get()->getRow(); // Access control data (assuming you still have those functions) $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/send_client_mail', $data); } else { return redirect()->to('/'); } } public function add_client_doc_tax() { $admin_id = session()->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $from = $this->request->getPost('from'); $to = $this->request->getPost('to'); $subject = $this->request->getPost('subject'); $message = $this->request->getPost('message'); $document = $this->request->getPost('documents'); $file_type = $this->request->getPost('file_type'); $created_at = date('d-m-Y'); $db = \Config\Database::connect(); $builder = $db->table('gss_client_mail_details'); $data = [ 'email_from' => $from, 'email_to' => $to, 'subject' => $subject, 'message' => $message, 'document' => json_encode($document), 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $builder->insert($data); $insertId = $db->insertID(); if ($insertId) { // Fetch mail details $builder = $db->table('gss_client_mail_details')->where('id', $insertId); $details = $builder->get()->getRow(); $documents = json_decode($details->document); $attachments = []; foreach ($documents as $doc) { if ($file_type === 'ce') { $path = FCPATH . 'public/doc_client_ec_uploads/' . $doc; } elseif ($file_type === 'ct') { $path = FCPATH . 'public/doc_client_tax_uploads/' . $doc; } elseif ($file_type === 'cd') { $path = FCPATH . 'public/doc_client_documents/' . $doc; } $attachments[] = $path; } // Get user email/signature $user = $db->table('gss_login')->where('user_id', $admin_id)->get()->getRow(); $cc = $user->email; $sign = $user->signature; // Prepare email $email = \Config\Services::email(); $config = [ 'protocol' => 'smtp', 'SMTPHost' => 'ssl://smtp.googlemail.com', 'SMTPPort' => 465, 'SMTPUser' => 'gssorganised@gmail.com', 'SMTPPass' => 'GSSKarthi@1236#', 'mailType' => 'html', 'charset' => 'utf-8', ]; $email->initialize($config); $email->setFrom($from, 'GSS'); $email->setTo($to); $email->setCC($cc); $email->setSubject($subject); $base_url = base_url(); $fullMessage = $message . '<br><br>Thanks and regards,<br><br>'; $fullMessage .= "<img src='{$base_url}public/assets/images/gss_logo.jpg' style='width:20%'><br>"; $fullMessage .= $sign; $email->setMessage($fullMessage); foreach ($attachments as $path) { $email->attach($path); } if ($email->send()) { return $this->response->setJSON(['result' => 1, 'message' => 'Your Email has successfully been sent.']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something Went Wrong!']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Insert Failed']); } } public function delete_client_ec() { $id = $this->request->getPost('id'); $ec_id = $this->request->getPost('ec_id'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_client_documents'); // Get EC JSON from DB $row = $builder->where('id', $id)->get()->getRow(); if ($row && $row->ec) { $ec_list = json_decode($row->ec); $new_ec_array = []; foreach ($ec_list as $key => $ec_entry) { if ($ec_entry->id != $ec_id) { $new_ec_array[] = $ec_entry; } } // Encode new EC list or set to empty string if none left $encoded_ec = !empty($new_ec_array) ? json_encode($new_ec_array) : ''; // Update record $builder->where('id', $id)->update(['ec' => $encoded_ec]); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No changes made.']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Record not found or EC empty.']); } } public function view_client_tax_documents() { $uri = service('uri'); $id = $uri->getSegment(2); if (!$id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $table = 'gss_doc_client_documents'; $details = $db->table($table)->where('id', $id)->get()->getRow(); if (!$details) { return redirect()->to('/'); } $user_type_id = session()->get('user_type_id'); $access = session()->get('access_details'); $data = [ 'details' => $details, 'user_type_id' => $user_type_id, 'access' => $access ]; return view('admin/view_client_tax_documents', $data); } public function get_client_tax_selected() { $id = $this->request->getPost('id'); $ec_ids = $this->request->getPost('ec_id'); // this should be an array $db = \Config\Database::connect(); // Step 1: Get client document row $clientRow = $db->table('gss_doc_client_documents')->where('id', $id)->get()->getRow(); if (!$clientRow) { return $this->response->setJSON(['result' => 0, 'message' => 'Client document not found.']); } $clientData = json_decode($clientRow->client); $ec_array = []; // Step 2: Extract tax_uploads based on ec_ids foreach ($ec_ids as $ec_id) { foreach ($clientData as $item) { if ($item->id == $ec_id) { $ec_array[] = $item->tax_upload; break; } } } $encodedDocs = json_encode($ec_array); $table = 'gss_client_tax_docs'; // Step 3: Check if tax docs already exist $existing = $db->table($table)->where('client_doc_id', $id)->get()->getRow(); // If exists, delete the old entry if ($existing) { $db->table($table)->where('client_doc_id', $id)->delete(); } // Step 4: Insert new record $insertData = [ 'client_doc_id' => $id, 'document' => $encodedDocs ]; $result = $db->table($table)->insert($insertData); if ($result) { return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Insert failed']); } } public function delete_client_tax() { $id = $this->request->getPost('id'); $tax_id = $this->request->getPost('tax_id'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_client_documents'); $get_owner = $builder->where('id', $id)->get()->getRow(); if (!$get_owner) { return $this->response->setJSON(['result' => 0, 'message' => 'Document not found.']); } $ownerData = json_decode($get_owner->client); $updatedArray = []; foreach ($ownerData as $key => $owner) { if ($owner->id != $tax_id) { $updatedArray[] = $owner; // keep this one } } $encodedClient = !empty($updatedArray) ? json_encode($updatedArray) : ''; $updateResult = $builder->where('id', $id)->update(['client' => $encodedClient]); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No change or failed to update.']); } } public function view_client_documents() { $uri = service('uri'); $id = $uri->getSegment(2); if (!$id) { return redirect()->to('/'); } $db = \Config\Database::connect(); $table = 'gss_doc_client_documents'; $details = $db->table($table)->where('id', $id)->get()->getRow(); if (!$details) { return redirect()->to('/'); } $user_type_id = session()->get('user_type_id'); $access = session()->get('access_details'); $data = [ 'details' => $details, 'user_type_id' => $user_type_id, 'access' => $access ]; return view('admin/view_client_docs', $data); } public function delete_client_doc() { $id = $this->request->getPost('id'); $doc_id = $this->request->getPost('doc_id'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_client_documents'); $get_doc = $builder->where('id', $id)->get()->getRow(); if (!$get_doc) { return $this->response->setJSON(['result' => 0, 'message' => 'Document not found.']); } $docs = json_decode($get_doc->upload_doc); $updatedDocs = []; foreach ($docs as $doc) { if ($doc->id != $doc_id) { $updatedDocs[] = $doc; // keep it } } $encoded = !empty($updatedDocs) ? json_encode($updatedDocs) : ''; $updateData = ['upload_doc' => $encoded]; $builder->where('id', $id)->update($updateData); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Nothing changed or failed to delete.']); } } public function edit_client_documents() { $uri = service('uri'); $id = $uri->getSegment(2); // Get the database connection $db = \Config\Database::connect(); // Fetch client document details $builder = $db->table('gss_doc_client_documents'); $builder->where('id', $id); $query = $builder->get(); $data['details'] = $query->getRow(); // Fetch active projects ordered by project_name $builder = $db->table('gss_doc_projects'); $builder->where('delete_status', 'ACTIVE'); $builder->orderBy('project_name', 'ASC'); $query = $builder->get(); $data['projects'] = $query->getResult(); // Get user type and access details from session $data['user_type_id'] = session()->get('user_type_id'); $data['access'] = session()->get('access_details'); return view('admin/edit_client_document', $data); } public function delete_doc_client_documents() { // Get the database connection $db = \Config\Database::connect(); // Get the 'id' from POST data $id = $this->request->getPost('id'); // Define the table and condition for deletion $table = 'gss_doc_client_documents'; $where = ['id' => $id]; // Data for soft deletion (marking 'delete_status' as INACTIVE) $data = ['delete_status' => 'INACTIVE']; // Perform the update query to mark as 'INACTIVE' $builder = $db->table($table); $builder->where($where); $builder->update($data); // Check if any rows were affected if ($db->affectedRows() > 0) { echo json_encode(['result' => 1, 'message' => 'Deleted successfully']); } else { echo json_encode(['result' => 0, 'message' => 'No rows affected']); } } public function get_client_doc_selected() { $id = $this->request->getPost('id'); $ec_id = $this->request->getPost('ec_id'); // Get the database connection $db = \Config\Database::connect(); // Check for the client document details using the ID $table = 'gss_doc_client_documents'; $where = ['id' => $id]; $builder = $db->table($table); $builder->where($where); $query = $builder->get(); $check = $query->getRow(); if ($check) { $get_ec = $check->upload_doc; $client_doc = json_decode($get_ec); $ec_array = []; foreach ($ec_id as $owner_ec) { foreach ($client_doc as $get_ec_id) { $ec_ids = $get_ec_id->id; $uploads = $get_ec_id->upload_doc; if ($ec_ids == $owner_ec) { $owner_ec_doc = $uploads; array_push($ec_array, $owner_ec_doc); } } } $ec_docs = json_encode($ec_array); // Check if the document already exists in gss_client_tax_docs $table = 'gss_client_tax_docs'; $where = ['client_doc_id' => $id]; $builder = $db->table($table); $builder->where($where); $query = $builder->get(); $check_row = $query->getRow(); if (empty($check_row)) { // If no row found, insert a new document $data = ['client_doc_id' => $id, 'document' => $ec_docs]; $result = $db->table($table)->insert($data); if ($result) { echo json_encode(['result' => 1]); } else { echo json_encode(['result' => 0]); } } else { // If a row is found, delete the old document and insert a new one $where = ['client_doc_id' => $id]; $db->table($table)->delete($where); $data = ['client_doc_id' => $id, 'document' => $ec_docs]; $result = $db->table($table)->insert($data); if ($result) { echo json_encode(['result' => 1]); } else { echo json_encode(['result' => 0]); } } } else { echo json_encode(['result' => 0, 'message' => 'Client document not found.']); } } public function get_doc_client_documents_list_project_wise() { $project = $this->request->getGet('project'); $project_status = $this->request->getGet('project_status'); // Get database connection $db = \Config\Database::connect(); // Build the query $builder = $db->table('gss_doc_client_documents A'); $builder->select('A.*, B.id as project_id, B.project_name'); $builder->join('gss_doc_projects B', 'B.id = A.project_id'); if ($project != "") { $builder->where('B.id', $project); } $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->orderBy('ABS(A.site_number)', 'ASC'); $query = $builder->get(); $result = $query->getResult(); return $this->response->setJSON($result ?: ['result' => 0]); } public function update_client_documents() { $session = session(); if (!$session->get('admin_id')) { return redirect()->to('/'); } $db = \Config\Database::connect(); $builder = $db->table('gss_doc_client_documents'); // Collect request data $id = $this->request->getPost('id'); $project_id = $this->request->getPost('project_id'); $site_number = $this->request->getPost('site_number'); $client_name = $this->request->getPost('client_name'); // Get existing data $det = $builder->where('id', $id)->get()->getRow(); if (!$det) { return $this->response->setJSON(['result' => 0, 'message' => "Invalid Document ID"]); } // 🔹 File Upload Function $uploadFile = function ($field_name, $target_dir, $old_file = '') { $file = $this->request->getFile($field_name); if ($file && $file->isValid() && !$file->hasMoved()) { $newName = preg_replace('/\s+/', '_', $file->getName()); $file->move($target_dir, $newName); return $newName; } return $old_file; }; // 🔹 Handle Multiple File Uploads $processUploads = function ($from_date, $to_date, $field_name, $upload_path, $existing_data) use ($uploadFile) { $result = []; $count = 0; $existing_data = json_decode($existing_data, true) ?? []; // 🔥 Ensure `$from_date` & `$to_date` are arrays $from_date = is_array($from_date) ? $from_date : []; $to_date = is_array($to_date) ? $to_date : []; foreach ($from_date as $key => $value) { if (!empty($value)) { $upload_file = !empty($_FILES[$field_name]['name'][$key]) ? $uploadFile($field_name . "[$key]", $upload_path) : ($existing_data[$key]['upload'] ?? ''); if (!$upload_file) { return false; } $result[] = [ 'id' => ++$count, 'from' => $value, 'to' => $to_date[$key] ?? '', 'upload' => $upload_file ]; } } return json_encode($result); }; // 🔹 Upload Files $booking_application = $uploadFile('booking_application', 'public/doc_client_booking_applications/', $det->booking_application); $sales_agreement_files = $uploadFile('sales_agreement_files', 'public/doc_client_sales_agreement/', $det->sales_agreement_files); $sales_deed = $uploadFile('sales_deed', 'public/doc_client_sales_deed/', $det->sales_deed); $client_khata = $uploadFile('client_khata', 'public/doc_client_khata/', $det->client_khata); // 🔹 Process Document Uploads $ec = $processUploads( $this->request->getPost('ec_from_date'), $this->request->getPost('ec_to_date'), 'ec_uploads', 'public/doc_client_ec_uploads/', $det->ec ); $client = $processUploads( $this->request->getPost('client_from_date'), $this->request->getPost('client_to_date'), 'client_tax', 'public/doc_client_tax_uploads/', $det->client ); $upload_doc = $processUploads( $this->request->getPost('documents_id'), $this->request->getPost('documents_name'), 'documents', 'public/doc_client_documents/', $det->upload_doc ); // 🔹 Ensure file uploads were successful if ($ec === false || $client === false || $upload_doc === false) { return $this->response->setJSON(['result' => 0, 'message' => "File Upload Failed"]); } // 🔹 Prepare Data for Update $modified_at = date('d-m-Y'); $data = [ 'project_id' => $project_id, 'site_number' => $site_number, 'client_name' => $client_name, 'booking_application' => $booking_application, 'sales_agreement_files' => $sales_agreement_files, 'sales_deed' => $sales_deed, 'ec' => $ec, 'client' => $client, 'client_khata' => $client_khata, 'upload_doc' => $upload_doc, 'modified_at' => $modified_at ]; // 🔹 Update Database $result = $builder->where('id', $id)->update($data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => "Updated Successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Update Failed"]); } } public function send_mail_client_contents($id = null) { $session = session(); $admin_id = $session->get('admin_id'); if ($admin_id) { // Get client document details $builder = \Config\Database::connect()->table('gss_doc_client_documents'); $data['details'] = $builder->where('id', $id)->get()->getRow(); if ($data['details']) { $project_id = $data['details']->project_id; // Get project details $projectBuilder = \Config\Database::connect()->table('gss_doc_projects'); $data['project'] = $projectBuilder->where('id', $project_id)->get()->getRow(); // Get admin user details $userBuilder = \Config\Database::connect()->table('gss_login'); $data['user'] = $userBuilder->where('user_id', $admin_id)->get()->getRow(); // Access control methods (assuming you define them elsewhere) $data['user_type_id'] = $this->access_id(); // custom function $data['access'] = $this->access_details(); // custom function return view('admin/send_mail_cleint_contents', $data); } else { return redirect()->to('/')->with('error', 'Invalid document ID.'); } } else { return redirect()->to('/'); } } public function add_client_doc_email() { $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $request = service('request'); $from = esc($request->getPost('from')); $to = esc($request->getPost('to')); $subject = esc($request->getPost('subject')); $message = esc($request->getPost('message')); $document = esc($request->getPost('document')); $file_type = esc($request->getPost('file_type')); $created_at = date('d-m-Y'); // Insert email details $db = \Config\Database::connect(); $builder = $db->table('gss_client_mail_details'); $insert_data = [ 'email_from' => $from, 'email_to' => $to, 'subject' => $subject, 'message' => $message, 'document' => $document, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $builder->insert($insert_data); $insert_id = $db->insertID(); if (!$insert_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Database insert failed.']); } // Get inserted row $details = $db->table('gss_client_mail_details') ->where('id', $insert_id) ->get() ->getRow(); // Get admin signature & cc email $login_row = $db->table('gss_login') ->where('user_id', $admin_id) ->get() ->getRow(); $sign = $login_row->signature ?? ''; $cc = $login_row->email ?? ''; // Build message $base_url = base_url(); $full_message = nl2br($details->message) . "<br><br>Thanks and regards,<br><br>" . "<img src='{$base_url}public/assets/images/gss_logo.jpg' style='width:20%'><br>" . $sign; // Determine file path $path_map = [ 'cba' => WRITEPATH . 'public/doc_client_booking_applications/', 'csa' => WRITEPATH . 'public/doc_client_sales_agreement/', 'csd' => WRITEPATH . 'public/doc_client_sales_deed/', 'ck' => WRITEPATH . 'public/doc_client_khata/', ]; $attachment_path = $path_map[$file_type] ?? ''; $full_file = $attachment_path . $document; if (!file_exists($full_file)) { return $this->response->setJSON(['result' => 0, 'message' => 'Attachment not found.']); } // Load email service and send $email = \Config\Services::email(); $config = [ 'protocol' => 'smtp', 'SMTPHost' => 'ssl://smtp.googlemail.com', 'SMTPPort' => 465, 'SMTPUser' => getenv('SMTP_USER'), // Make sure these are in .env 'SMTPPass' => getenv('SMTP_PASS'), 'mailType' => 'html', 'charset' => 'utf-8', 'newline' => "\r\n", 'wordWrap' => true ]; $email->initialize($config); $email->setFrom($from, 'GSS'); $email->setTo($to); $email->setCC($cc); $email->setSubject($subject); $email->setMessage($full_message); $email->attach($full_file); if ($email->send()) { return $this->response->setJSON(['result' => 1, 'message' => 'Your Email has successfully been sent.']); } else { log_message('error', $email->printDebugger(['headers'])); return $this->response->setJSON(['result' => 0, 'message' => 'Email failed to send.']); } } public function delete_client_khata() { $request = service('request'); $id = $request->getPost('id'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_client_documents'); $builder->where('id', $id); $builder->update(['client_khata' => '']); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0]); } } public function delete_client_sales_deed() { $request = service('request'); $id = $request->getPost('id'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_client_documents'); $builder->where('id', $id); $builder->update(['sales_deed' => '']); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0]); } } public function delete_client_sales_agreement() { $request = service('request'); $id = $request->getPost('id'); $db = \Config\Database::connect(); $builder = $db->table('gss_doc_client_documents'); $builder->where('id', $id); $builder->update(['sales_agreement_files' => '']); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } else { return $this->response->setJSON(['result' => 0]); } } public function get_status_report_balance_agree_amt() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $project = $this->request->getpost('project_id'); $tot_agree_due_amt = $gss_model->get_total_agree_due_amt($project); $total_agreement_due_amount = 0; $total_registration_due_amount = 0; foreach($tot_agree_due_amt as $tada) { $total_agreement_due_amt = $tada->sales_agreement_due_amount; $total_agreement_due_amount += $total_agreement_due_amt; $total_reg_due_amt = $tada->registration_due_amount; $total_registration_due_amount += $total_reg_due_amt; } $received_agreement_amt = $gss_model->get_received_agree_amt($project); $received_agreement_amount = 0; $received_registration_amount = 0; foreach($received_agreement_amt as $raa) { $received_agree_amt = $raa->agreement_amount; $received_agreement_amount += is_numeric($received_agree_amt); $received_due_amt = $raa->registration_amount; $received_registration_amount += is_numeric($received_due_amt); } $from_date = ""; $to_date = ""; $total_paid = 0; $tot_agr_amt = 0; $tot_booking_amt = 0; $total_paid_reg = $gss_model->payment_reports_receivable($from_date,$to_date,$project); foreach($total_paid_reg as $tpr) { $tot_booking = $tpr['booking_amount1']; $tot_booking_amt += $tot_booking; $tot_agr = $tpr['agreement_amount2']; $tot_agr_amt += is_numeric($tot_agr); $tot_paid = $tpr['subtotal2']; $total_paid += $tot_paid; } $received_agr_amount = $tot_booking_amt+$tot_agr_amt; $received_reg_amount = $total_paid; $balance_agree_amount = $total_agreement_due_amount - $received_agreement_amount; $balance_reg_amount = $total_registration_due_amount - $received_registration_amount; $total_dimn_result = $gss_model->total_marketing_dimension_report($project); $booked_dimn_result = $gss_model->total_booked_dimension_report($project); return $this->response->setJSON(['result'=>1,'total_dimension'=>$total_dimn_result,'booked_dimnsion'=>$booked_dimn_result, 'balance_agreement_amount'=>$balance_agree_amount,'received_reg_amount'=>$received_reg_amount,'received_registration_amount'=>$received_registration_amount,'balance_reg_amount'=>$balance_reg_amount,'received_agreement_amount'=>$received_agreement_amount,'received_agr_amount'=>$received_agr_amount]); } public function add_report_status() { $gss_model=new Gss_model(); $table = 'gss_report_status'; $gss_model->table_truncate($table); $project_id_datewise = $this->request->getpost('project_id_datewise'); $agr_type = $this->request->getpost('agr_type'); $from_date_datewise = $this->request->getpost('from_date_datewise'); $to_date_datewise = $this->request->getpost('to_date_datewise'); $budget_from_date_datewise = $this->request->getpost('budget_from_date_datewise'); $budget_to_date_datewise = $this->request->getpost('budget_to_date_datewise'); $khata_status = $this->request->getpost('khata_status'); $project_ownership = $this->request->getpost('project_ownership'); $s1_project_type = $this->request->getpost('s1_project_type'); $handled_by = $this->request->getpost('handled_by'); $reference = $this->request->getpost('reference'); $logistic = $this->request->getpost('logistic'); $data = array('project_status'=>$s1_project_type,'project'=>$project_id_datewise,'from_date'=>$from_date_datewise,'type'=>$agr_type,'to_date'=>$to_date_datewise,'budget_from'=>$budget_from_date_datewise,'budget_to'=>$budget_to_date_datewise,'project_ownership'=>$project_ownership,'khata_status'=>$khata_status,'handled_by'=>$handled_by,'reference'=>$reference,'logistic'=>$logistic,'delete_status'=>'ACTIVE'); $result = $gss_model->insert1($table,$data); if($result) { return $this->response->setJSON(['result'=>1,'message'=>$result]); } else { return $this->response->setJSON(['result'=>0,'message'=>'Data Already Exist']); } } public function get_status_report_type() { $gss_model=new Gss_model(); $table= 'gss_report_status'; $id = $this->request->getpost('id'); $where = array('id'=>$id,'delete_status'=>'ACTIVE'); $result = $gss_model->get_where_row($table,$where); //print_r($result);die(); if($result) { return $this->response->setJSON(['details'=>$result,'result'=>1]); } else { return $this->response->setJSON(['result'=>0]); } } public function get_report_status_details() { $admin_id = session()->get('admin_id'); if($admin_id) { //$project=$this->uri->segement(2); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/report_status_grid',$data); } else { redirect('/'); } } public function get_report_status_unbooked_details() { $admin_id = session()->get('admin_id'); if($admin_id) { //$project=$this->uri->segement(2); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/report_status_unbooked_grid',$data); } else { redirect('/'); } } public function get_status_agree_due_reports() { $gss_model=new Gss_model(); $project = $_GET['project']; $result = $gss_model->get_status_agree_due_reports($project); if($result) { return $this->response->setJSON([$result]); } else { return $this->response->setJSON(['result'=>0]); } } public function auto_complete_vendor_name() { $gss_model=new Gss_model(); $keyword = $this->request->getGet('term'); $data1 = $gss_model->GetRowlog($keyword); foreach ($data1 as $row) { $data[] = $row->vendor_name; } return $this->response->setJSON($data); } public function invoice_form() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $table='gss_new_projects'; $where_project = array('delete_status'=>'ACTIVE'); $order_by2='project_name'; $data['project_names']=$gss_model->get_where_result_alphabetical($table,$where_project,$order_by2); $table= 'gss_bank_details' ; $where = array('delete_status'=>'ACTIVE'); $order_by='holder_name'; $data['bank_name'] = $gss_model->get_where_result_alphabetical($table,$where_project,$order_by); //$data['invoice'] = $this->gss_model->get_invoice_id(); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/invoice',$data); } else { redirect('/'); } } public function add_invoice_details() { $table = 'gss_invoice_details'; $gss_model = new Gss_model(); $invoice_number = $this->request->getPost('invoice_number'); $project_name = $this->request->getPost('project_name'); $site_list = $this->request->getPost('site_list'); // No need for [] $site_number = $this->request->getPost('site_number'); // No need for [] $invoice_type = $this->request->getPost('invoice_type'); $to = $this->request->getPost('to'); $total_sqft = (float) ($this->request->getPost('total_sqft') ?? 0); $rate_per_sqft = (float) ($this->request->getPost('rate_per_sqft') ?? 0); $total_amt = (float) ($this->request->getPost('total_amt') ?? 0); $sgst = (float) ($this->request->getPost('sgst') ?? 0); $cgst = (float) ($this->request->getPost('cgst') ?? 0); $total_withgst_amt = (float) ($this->request->getPost('total_withgst_amt') ?? 0); $bank_holder_name = $this->request->getPost('bank_holder_name'); // ✅ Ensure values are properly calculated $total_amt1 = $total_amt * $total_sqft; $total_sgst = round(($total_amt * $sgst) / 100); $total_cgst = round(($total_amt * $cgst) / 100); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $data = [ 'invoice_number' => $invoice_number, 'project_id' => $project_name, 'site_ids' => json_encode($site_list), 'invoice_type' => $invoice_type, 'invoice_to' => $to, 'total_sqft' => $total_sqft, 'rate_per_sqft' => $rate_per_sqft, 'without_gst_total_amt' => $total_amt, 'sgst' => $sgst, 'cgst' => $cgst, 'with_gst_total_amt' => $total_withgst_amt, 'modified_at' => $created_at, 'created_at' => $created_at, 'delete_status' => 'ACTIVE', 'site_numbers' => json_encode($site_number), 'total_sgst' => $total_sgst, 'total_cgst' => $total_cgst, 'bank_name' => $bank_holder_name ]; // Condition for checking if the data already exists $condition = [ 'invoice_number' => $invoice_number, 'project_id' => $project_name, 'site_ids' => json_encode($site_list), 'invoice_type' => $invoice_type, 'invoice_to' => $to, 'total_sqft' => $total_sqft, 'rate_per_sqft' => $rate_per_sqft, 'without_gst_total_amt' => $total_amt, 'sgst' => $sgst, 'cgst' => $cgst, 'with_gst_total_amt' => $total_withgst_amt, 'total_sgst' => $total_sgst, 'total_cgst' => $total_cgst, 'bank_name' => $bank_holder_name ]; $get_det = $gss_model->get_where_row($table, $condition); if (empty($get_det)) { if ($invoice_type == "Tax Invoice") { $in_type = "tax"; } elseif ($invoice_type == "Proforma Invoice") { $in_type = "proforma"; } $result = $gss_model->insert1($table, $data); $site_numbers = $this->request->getPost('site_number'); $explode = explode(",", $site_numbers); foreach ($explode as $values) { $tble_sites = 'gss_new_sites'; $condition_sites = ['project_id' => $project_name, 'site_number' => $values]; $update_data = ['billing_status' => $invoice_type, 'invoice_no' => $invoice_number]; $gss_model->update1($tble_sites, $condition_sites, $update_data); } return $this->response->setJSON(['result' => 1, 'message' => $result, 'in_type' => $invoice_type]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Data Already Exist']); } } public function invoice_print() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $id=$_GET['id']; // print_r($id);die(); $table ='gss_bank_details'; $where = ['delete_status'=>'ACTIVE']; $data['bank_name'] = $gss_model->get_all_bank_details($table,$where); $data['bank_address'] = $gss_model->get_all_bank_details($table,$where); // $data['details']=$gss_model->get_where_row_for_print($id); $data['details'] = $gss_model->get_where_row_for_print('gss_invoice_details', $id); // print_r($data['details']); // die(); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/invoice_print',$data); } else { redirect('/'); } } public function update_invoice_number() { $gss_model = new Gss_model(); $table = 'gss_invoice_details'; $db = \Config\Database::connect(); $id = $this->request->getPost('id'); $invoice_no = $this->request->getPost('invoice_no'); $pro_name = $this->request->getPost('pro_name'); $pro_description = $this->request->getPost('pro_description'); $pro_dept = $this->request->getPost('pro_dept'); $pro_currency = $this->request->getPost('pro_currency'); $a = date("y"); $b = $a + 1; $new_invoice = 'GSS/'.$a.'-'.$b.'/'.$invoice_no; $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $data = [ 'invoice_no' => $new_invoice, 'modified_at' => $created_at ]; $where = ['id' => $id]; // Attempt to update the invoice number $result = $gss_model->update1($table, $where, $data); if ($result) { return $this->response->setJSON([ 'result' => 1, 'message' => 'Invoice number updated successfully' ]); } else { // If update fails, log error and return error message log_message('error', 'Failed to update invoice number for ID: ' . $id); return $this->response->setJSON([ 'result' => 0, 'message' => 'Failed to update invoice number' ]); } } public function get_invoice_no() { $gss_model=new Gss_model(); $type=$_REQUEST['type']; $holder=$_REQUEST['holder']; $invoice = $gss_model->get_invoice_id($type,$holder); return $this->response->setJSON([$invoice]); } public function get_sites_sqft() { $gss_model=new Gss_model(); $project_id=$this->request->getpost('project_id'); $site_id=$this->request->getpost('site_id'); $total_sqft=0; $site_ids=array(); $site_numbers=array(); foreach($project_id as $key=>$project_ids) { $details=$gss_model->get_where_result_sites_sqft($project_ids,$site_id[$key]); if($details) { $total_sqft+=$details->total_in_sqft; array_push($site_ids,$details->site_id); array_push($site_numbers,$details->site_number); } } if($total_sqft) { return $this->response->setJSON(['result'=>1,'message'=>$total_sqft,'site_id'=>$site_ids,'site_number'=>$site_numbers]); } else { return $this->response->setJSON(['result'=>0,'message'=>'Not found']); } } // cancellation starts here //Branches list public function get_branches_list() { $db = \Config\Database::connect(); $table = 'gss_branches'; $where = ['delete_status' => 'ACTIVE']; // 🔹 Fetch active branches $result = $db->table($table)->where($where)->get()->getResult(); if ($result) { return $this->response->setJSON(['result' => 1, 'result1' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } //Cancellation form public function cancellation_form() { $admin_id = session()->get('admin_id'); if($admin_id) { $GssNewProjectsModel = new GssNewProjectsModel(); $BrokerModel = new BrokerModel(); $broker_table = 'gss_brokers'; $project_table = 'gss_new_projects'; $where_project = array('delete_status'=>'ACTIVE'); $where_reference = array('delete_status'=>'ACTIVE','type'=>'Executives'); $where_associate = array('delete_status'=>'ACTIVE','type'=>'Associate'); $where_subassociate = array('delete_status'=>'ACTIVE','type'=>'Sub Associate'); $order_by_project = 'project_name'; $order_by_associate = 'associate_name'; $order_by_reference = 'associate_name'; $data['associates'] = $BrokerModel ->get_where_result_alphabetical($broker_table,$where_associate,$order_by_associate); $data['subassociates'] = $BrokerModel ->get_where_result_alphabetical($broker_table,$where_subassociate,$order_by_associate); $data['projects'] = $GssNewProjectsModel->get_where_result_alphabetical($project_table,$where_project,$order_by_project); $data['reference'] = $BrokerModel ->get_where_result_alphabetical($broker_table,$where_reference,$order_by_reference); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/cancellation_form',$data); } else { redirect('/'); } } public function add_cancellation_details() { $db = \Config\Database::connect(); $request = service('request'); // 🔹 Get request values $booking_id = $request->getPost('booking_id'); $project_id = $request->getPost('project_id'); $site_number = $request->getPost('site_number'); $refunded = $request->getPost('refunded'); $refunded_to = $request->getPost('refunded_to'); $refunded_date = $request->getPost('refunded_date'); $total = $request->getPost('total'); $due_amount = str_replace(',', '', $request->getPost('due_amount')); $due_with = $request->getPost('due_with'); $refund_amount = str_replace(',', '', $request->getPost('refunded_amount')); $cancellation_date = $request->getPost('cancellation_date'); $refunded_payment_mode = $request->getPost('refunded_payment_mode'); $note = $request->getPost('note'); // 🔹 Format cancellation date if (!empty($cancellation_date)) { $cancellation_date = date('Y-m-d', strtotime($cancellation_date)); } // 🔹 Check booking status $booking = $db->table('gss_bookings') ->where('booking_id', $booking_id) ->get() ->getRow(); if (!$booking) { return $this->response->setJSON(['result' => 0, 'message' => 'Booking not found']); } if ($booking->booking_status === 'CANCELLED') { return $this->response->setJSON(['result' => 2, 'message' => 'Site already cancelled']); } // 🔹 File Upload Handling helper('filesystem'); $file_name = ""; $file_name1 = ""; if ($file = $this->request->getFile('refunded_request_letter')) { if ($file->isValid() && !$file->hasMoved()) { $file_name = time() . $file->getClientName(); $file->move('cancellation_uploads/', $file_name); } } if ($file1 = $this->request->getFile('cancellation_agreement_image')) { if ($file1->isValid() && !$file1->hasMoved()) { $file_name1 = time() . $file1->getClientName(); $file1->move('cancellation_uploads/', $file_name1); } } // 🔹 Prepare Data for Cancellation Table $data = [ 'booking_id' => $booking_id, 'refunded' => $refunded, 'refunded_request_letter' => $file_name, 'cancellation_date' => $cancellation_date, 'cancellation_agreement_image' => $file_name1, 'created_at' => date('Y-m-d H:i:s', time()) ]; $cancel_table = 'gss_cancellations'; $booking_table = 'gss_bookings'; // 🔹 Insert Cancellation Data $result = $db->table($cancel_table)->insert($data); $cancellation_id = $db->insertID(); if (!$result) { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong']); } // 🔹 Handle Refund Details if (!empty($refund_amount)) { $payment_data_array = []; foreach ($refund_amount as $key => $val) { $refunded_date_value = $refunded_date[$key] ?? '0000-00-00'; $mode = $refunded_payment_mode[$key] ?? ''; // Set payment details based on mode $cheque_no = '0'; $cheque_date = '0000-00-00'; $bank_name = '0'; $vtr_no = '0'; $online_date = '0000-00-00'; if ($mode === 'Cheque') { $cheque_no = $request->getPost('cheque_no')[$key] ?? '0'; $cheque_date = $request->getPost('cheque_date')[$key] ?? '0000-00-00'; $bank_name = $request->getPost('bank_name')[$key] ?? '0'; } elseif ($mode === 'Online Payment') { $vtr_no = $request->getPost('vtr_no')[$key] ?? '0'; $online_date = $request->getPost('online_date')[$key] ?? '0000-00-00'; } $payment_data_array[] = [ 'cancellation_id' => $cancellation_id, 'booking_id' => $booking_id, 'total' => $total, 'due_amount' => $due_amount[$key], 'refunded_payment_mode' => $mode, 'refunded_date' => $refunded_date_value, 'refunded_amount' => $val, 'due_with' => $due_with[$key], 'vtr_no' => $vtr_no, 'online_date' => $online_date, 'cheque_no' => $cheque_no, 'cheque_date' => $cheque_date, 'bank_name' => $bank_name, 'delete_status' => 'ACTIVE', 'created_at' => date('Y-m-d H:i:s', time()) ]; } // 🔹 Insert Refund Data $db->table('gss_cancellation_refunds')->insertBatch($payment_data_array); } // 🔹 Update Booking Status if (is_string($due_amount) && strlen($due_amount) > 0 && $due_amount[0] == '0' && $refunded === "Yes") { $booking_status = 'REFUNDED'; } else { $booking_status = 'REFUND_PENDING'; } if ($refunded === "No") { $booking_status = 'CANCELLED'; } $db->table($booking_table)->where('booking_id', $booking_id)->update(['booking_status' => $booking_status]); return $this->response->setJSON(['result' => 1, 'message' => 'Details added successfully']); } //Cancellation list public function cancellations_list() { $admin_id = session()->get('admin_id'); if($admin_id) { $GssNewProjectsModel = new GssNewProjectsModel(); $BrokerModel = new BrokerModel(); $broker_table = 'gss_brokers'; $project_table = 'gss_new_projects'; $where_project = array('delete_status'=>'ACTIVE','project_status'=>'ONGOING'); $where_reference = array('delete_status'=>'ACTIVE','type'=>'Executives'); $where_associate = array('delete_status'=>'ACTIVE','type'=>'Associate'); $data['associates'] = $BrokerModel ->get_where_result($broker_table,$where_associate); $data['projects'] = $GssNewProjectsModel->get_where_result($project_table,$where_project); $data['reference'] = $BrokerModel ->get_where_result($broker_table,$where_reference); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/cancellation_list',$data); } else { redirect('/'); } } //Cancellation list public function cancellation_list() { $db = \Config\Database::connect(); $builder = $this->db->table('gss_cancellations A') ->select('E.total_in_sqft, A.*, B.*, C.*, D.*, F.*, A.cancellation_id as cancel_id') ->join('gss_bookings B', 'B.booking_id = A.booking_id') ->join('gss_booking_details C', 'C.booking_id = B.booking_id') ->join('gss_new_projects D', 'D.project_id = B.project_id') ->join('gss_new_sites E', 'E.project_id = D.project_id AND C.site_number = E.site_number') ->join('gss_cancellation_refunds F', 'F.booking_id = A.booking_id AND F.cancellation_id = A.cancellation_id', 'left') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('C.delete_status', 'ACTIVE') ->where('D.delete_status', 'ACTIVE') ->where('E.delete_status', 'ACTIVE') ->orderBy('A.cancellation_id', 'DESC'); $result = $builder->get()->getResult(); $array = []; foreach ($result as $value) { $num = str_replace(',', '', $value->refunded_amount); $explrestunits = ""; if (strlen($num) > 3) { $lastthree = substr($num, strlen($num) - 3, strlen($num)); $restunits = substr($num, 0, strlen($num) - 3); $restunits = (strlen($restunits) % 2 == 1) ? "0" . $restunits : $restunits; $expunit = str_split($restunits, 2); foreach ($expunit as $i => $unit) { $explrestunits .= ($i == 0) ? (int)$unit . "," : $unit . ","; } $refunded_amount_total = $explrestunits . $lastthree; } else { $refunded_amount_total = $num; } $data = [ 'cancel_id' => $value->cancel_id, 'customer_name' => $value->customer_name, 'project_name' => $value->project_name, 'site_number' => $value->site_number, 'total_in_sqft' => $value->total_in_sqft, 'refunded' => $value->refunded, 'refunded_date' => $value->refunded_date, 'refunded_amount' => $refunded_amount_total, // No function call, directly formatted inside the loop 'note' => $value->note ]; array_push($array, $data); } if ($array) { return $this->response->setJSON($array); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Data not found']); } } public function cancellation_details() { // Get the admin ID from session $admin_id = session()->get('admin_id'); $model = new \App\Models\GssModel(); // Check if admin is logged in if ($admin_id) { // Define necessary variables $broker_table = 'gss_brokers'; $uri=service('uri'); $cancellation_id = $uri->getSegment(2); // Get cancellation details $cancel_result = $model->cancellation_details2($cancellation_id); // Fetch the cancellation payment, agreement, and total amount details $data['payment'] = $model->cancellation_payment_details($cancellation_id); $data['agreement'] = $model->cancellation_agreement_details($cancellation_id); $data['total_amount'] = $model->cancellation_total_amount($cancellation_id); // Fetch cancellation details based on whether the refund status is 'No' or not if ($cancel_result->refunded == 'No') { $data['details'] = $model->cancellation_details_no_refunds($cancellation_id); } else { $data['detailss'] = $model->cancellation_details1($cancellation_id); } // Set user type ID and access details $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); // Load the view with the cancellation details return view('admin/cancellation_details', $data); } else { // Redirect to the home page if admin is not logged in return redirect()->to('/'); } } public function cancellation_preview() { $this->db = \Config\Database::connect(); helper('url'); // Load URL helper for redirection $session = session(); $admin_id = $session->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $cancellation_id = $this->request->getUri()->getSegment(2); // Get cancellation details $cancellation = $this->db->table('gss_cancellations') ->where('cancellation_id', $cancellation_id) ->get() ->getRow(); if (!$cancellation) { return redirect()->to('/'); // Redirect if no cancellation found } $booking_id = $cancellation->booking_id; // Get site booking details (Moved function logic inside) $site_result = $this->db->table('gss_bookings A') ->select('A.*, B.*, C.*, D.registration_date, A.booking_status as a_booking_status, B.booking_status as b_booking_status') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->join('gss_booking_details C', 'C.booking_id = A.booking_id') ->join('gss_plot_payments D', 'D.booking_id = A.booking_id', 'left') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('A.booking_id', $booking_id) ->orderBy('A.booking_id', 'DESC') ->get() ->getRow(); $data['site_result'] = $site_result ? [ 'booking_id' => $site_result->booking_id, 'customer_name' => $site_result->customer_name, 'email' => $site_result->email, 'mobile' => trim($site_result->mobile1 . ',' . $site_result->mobile2, ','), 'project_name' => $site_result->project_name, 'site_number' => $site_result->site_number, 'registration_date' => $site_result->registration_date, ] : null; // Get installment details $data['instal_result'] = $this->db->table('gss_booking_installments') ->where(['booking_id' => $booking_id, 'delete_status' => 'ACTIVE']) ->get() ->getRow(); // Get project details $project = $this->db->table('gss_bookings') ->where('booking_id', $booking_id) ->get() ->getRow(); if (!$project) { return redirect()->to('/'); } $project_id = $project->project_id; $data['project'] = $this->db->table('gss_new_projects') ->where('project_id', $project_id) ->get() ->getRow(); // Get land owner details $data['land_owner'] = $this->db->table('gss_land_owners') ->where('owner_id', $data['project']->land_owner_id) ->get() ->getRow(); // Get refund details (Moved function logic inside) $data['refunds'] = $this->db->table('gss_cancellations A') ->select('*') ->join('gss_cancellation_refunds B', 'B.cancellation_id = A.cancellation_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('A.cancellation_id', $cancellation_id) ->get() ->getResult(); // Get user type ID (Moved function logic inside) $data['user_type_id'] = session()->get('user_type_id'); // Get access details (Moved function logic inside) $data['access'] = session()->get('access'); // Load view based on land owner name if ($data['land_owner']->name == 'GSS Project Consultants') { return view('admin/gss_cancellation_receipt', $data); } else { return view('admin/gss_cancellation_ack', $data); } } public function check_booking_status() { $db = \Config\Database::connect(); $request = service('request'); $booking_id = $request->getPost('booking_id'); if (!$booking_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Booking ID is required']); } $table = 'gss_bookings'; $where = ['booking_id' => $booking_id]; // 🔹 Fetch booking details $details = $db->table($table)->where($where)->get()->getRow(); if ($details) { if ($details->booking_status != 'REFUND_PENDING' && $details->booking_status != 'REFUNDED') { return $this->response->setJSON(['result' => 1]); } else { return $this->response->setJSON(['result' => 0]); } } else { return $this->response->setJSON(['result' => 0]); } } public function edit_cancellation_details() { $session = session(); $admin_id = $session->get('admin_id'); if ($admin_id) { $db = \Config\Database::connect(); $cancellation_id = $this->request->getUri()->getSegment(2); // Fetch associates, sub-associates, projects, and references $data['associates'] = $this->fetch_data('result_alphabetical', 'gss_brokers', ['delete_status' => 'ACTIVE', 'type' => 'Associate'], 'associate_name'); $data['subassociates'] = $this->fetch_data('result_alphabetical', 'gss_brokers', ['delete_status' => 'ACTIVE', 'type' => 'Sub Associate'], 'associate_name'); $data['projects'] = $this->fetch_data('result_alphabetical', 'gss_new_projects', ['delete_status' => 'ACTIVE', 'project_status' => 'ONGOING'], 'project_name'); $data['reference'] = $this->fetch_data('result_alphabetical', 'gss_brokers', ['delete_status' => 'ACTIVE', 'type' => 'Executives'], 'associate_name'); // Fetch cancellation details $data['details'] = $this->fetch_data('cancellation_details', null, ['A.cancellation_id' => $cancellation_id]); $data['cancel_result'] = $this->fetch_data('cancellation', null, ['A.cancellation_id' => $cancellation_id]); $data['mul_refunds'] = $this->fetch_data('result_alphabetical', 'gss_cancellation_refunds A', ['A.cancellation_id' => $cancellation_id, 'A.delete_status' => 'ACTIVE'], 'A.id'); $data['latest_due_amount'] = $this->fetch_data('single_row', 'gss_cancellation_refunds', ['delete_status' => 'ACTIVE', 'cancellation_id' => $cancellation_id], 'id', 1); // Fetch booking details $cancellation_details = $this->fetch_data('single_row', 'gss_cancellations', ['cancellation_id' => $cancellation_id]); if ($cancellation_details) { $can_booking_id = $cancellation_details->booking_id; $data['get_install_amount'] = $this->fetch_data('result_alphabetical', 'gss_plot_payments', ['booking_id' => $can_booking_id, 'install_delete_status' => 'ACTIVE']); $data['get_agreement_amount'] = $this->fetch_data('single_row', 'gss_plot_payments', ['booking_id' => $can_booking_id, 'agreement_delete_status' => 'ACTIVE']); } // Fetch branches $data['branch'] = $this->fetch_data('result_alphabetical', 'gss_branches', ['delete_status' => 'ACTIVE'], 'branch'); // Access details $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/edit_cancellation', $data); } else { return redirect()->to('/'); } } private function fetch_data($action, $table = null, $where = [], $order_by = null, $limit = null) { $db = \Config\Database::connect(); if ($action == 'cancellation_details' || $action == 'cancellation') { // Special case for specific queries $builder = $db->table('gss_cancellations A') ->join('gss_bookings B', 'B.booking_id = A.booking_id') ->join('gss_booking_details C', 'C.booking_id = B.booking_id') ->join('gss_new_projects D', 'D.project_id = B.project_id'); if ($action == 'cancellation_details') { $builder->join('gss_new_sites E', 'E.project_id = D.project_id AND C.site_number = E.site_number') ->select('E.total_in_sqft, A.*, B.*, C.*, D.*, A.cheque_no as refunded_check_no, A.cheque_date as refunded_check_date, A.bank_name as refunded_bank_name, A.due_amount, A.due_with, A.vtr_no as refunded_vtr_no, A.online_date as refunded_online_date, A.note'); } else { $builder->select('A.*, B.*, C.*, D.*, A.cheque_no as refunded_check_no, A.cheque_date as refunded_check_date, A.bank_name as refunded_bank_name, A.due_amount, A.due_with'); } return $builder->where($where)->get()->getRow(); } // For general queries if (!$table) { throw new \Exception("Table name must be provided for action: " . $action); } $builder = $db->table($table)->where($where); if ($order_by) { $builder->orderBy($order_by, 'ASC'); } if ($limit) { $builder->limit($limit); } switch ($action) { case 'result_alphabetical': return $builder->get()->getResult(); case 'single_row': return $builder->get()->getRow(); default: return null; } } //Delete cancellation list public function delete_cancellation_list() { $cancellation_id = $this->request->getUri()->getSegment(2); // Get the second segment from URL if (!$cancellation_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid ID']); } // Update the cancellation status to INACTIVE $result = $this->db->table('gss_cancellations') ->where('cancellation_id', $cancellation_id) ->update(['delete_status' => 'INACTIVE']); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No changes made']); } } public function delete_refunds() { $id = $this->request->getPost('id'); // Get 'id' from POST request if (!$id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid ID']); } $refund_table = 'gss_cancellation_refunds'; $booking_table = 'gss_bookings'; // Fetch the booking_id linked to this refund $get_booking_id = $this->db->table($refund_table) ->where('id', $id) ->get() ->getRow(); if (!$get_booking_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Refund not found']); } $booking_id = $get_booking_id->booking_id; // Fetch the current booking status $get_status = $this->db->table($booking_table) ->where('booking_id', $booking_id) ->get() ->getRow(); if (!$get_status) { return $this->response->setJSON(['result' => 0, 'message' => 'Booking not found']); } // If booking status is REFUNDED, change it to REFUND_PENDING if ($get_status->booking_status == 'REFUNDED') { $this->db->table($booking_table) ->where('booking_id', $booking_id) ->update(['booking_status' => 'REFUND_PENDING']); if ($this->db->affectedRows() > 0) { // Now delete the refund record $result = $this->db->table($refund_table)->where('id', $id)->delete(); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } } } else { // Directly delete refund entry $result = $this->db->table($refund_table)->where('id', $id)->delete(); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted!']); } } return $this->response->setJSON(['result' => 0, 'message' => 'Deletion failed']); } public function update_cancellation_details() { $request = service('request'); $db = \Config\Database::connect(); $project = $request->getPost('project_id'); $site_number = $request->getPost('site_number'); $refund_id = $request->getPost('refunded_id'); $booking_id = $request->getPost('booking_id'); $cancellation_id = $request->getPost('cancellation_id'); $refunded = $request->getPost('refunded'); $refunded_to = $request->getPost('refunded_to'); $refunded_date = $request->getPost('new_refunded_date'); $total = str_replace(',', '', $request->getPost('total')); $due_amount = $request->getPost('new_due_amount'); if (is_array($due_amount)) { $due_amount = array_map(fn($v) => str_replace(',', '', $v), $due_amount); } $due_with = $request->getPost('new_due_with'); $refund_amount = $request->getPost('new_refunded_amount'); $refund_amount = is_array($refund_amount) ? array_map(fn($v) => str_replace(',', '', $v), $refund_amount) : []; $cancellation_date = $request->getPost('cancellation_date'); if ($cancellation_date) { $cancellation_date = (new DateTime($cancellation_date))->format('Y-m-d'); } else { $cancellation_date = null; } $refunded_payment_mode = $request->getPost('new_refunded_payment_mode') ?? []; $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $note = $request->getPost('note'); $data = [ 'booking_id' => $booking_id, 'refunded' => $refunded, 'cancellation_date' => $cancellation_date, 'created_at' => $created_at ]; $builder = $db->table('gss_cancellations'); $builder->where('cancellation_id', $cancellation_id); $builder->update($data); if ($db->affectedRows() > 0) { $payments = $request->getPost('edit_payment_id') ?? []; $installments = $request->getPost('installment_amount') ?? []; $installments = is_array($installments) ? array_map(fn($v) => str_replace(',', '', $v), $installments) : []; $edit_booking_id = $request->getPost('edit_booking_id'); $sale_agree_amount = str_replace(',', '', $request->getPost('sale_agree_amount')); // Update agreement amount $db->table('gss_plot_payments') ->where('booking_id', $edit_booking_id) ->update(['agreement_amount' => $sale_agree_amount]); // Update installment amounts foreach ($payments as $i => $payment_id) { $db->table('gss_plot_payments') ->where('payment_id', $payment_id) ->update(['installment_amount1' => $installments[$i] ?? 0]); } $payment_data_array = []; foreach ($refund_amount as $key => $amount) { $refunded_date_item = $refunded_date[$key] ?? '0000-00-00'; $mode = $refunded_payment_mode[$key] ?? 'Other'; $cheque_no = '0'; $cheque_date = '00-00-0000'; $bank_name = '0'; $vtr_no = '0'; $online_date = '00-00-0000'; if ($mode === 'Cheque') { $cheque_no = $request->getPost('new_cheque_no')[$key] ?? '0'; $cheque_date = $request->getPost('new_cheque_date')[$key] ?? '00-00-0000'; $bank_name = $request->getPost('new_bank_name')[$key] ?? '0'; } elseif ($mode === 'Online Payment') { $vtr_no = $request->getPost('new_vtr_no')[$key] ?? '0'; $online_date = $request->getPost('new_online_date')[$key] ?? '00-00-0000'; } $payment_data_array[] = [ 'cancellation_id' => $cancellation_id, 'booking_id' => $booking_id, 'total' => $total, 'due_amount' => $due_amount[$key] ?? 0, 'refunded_payment_mode' => $mode, 'refunded_date' => $refunded_date_item, 'refunded_amount' => $amount, 'due_with' => $due_with[$key] ?? '', 'vtr_no' => $vtr_no, 'online_date' => $online_date, 'cheque_no' => $cheque_no, 'cheque_date' => $cheque_date, 'bank_name' => $bank_name, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $booking_status = 'CANCELLED'; if (($due_amount[$key] ?? 0) == 0 && $refunded == "Yes") { $booking_status = 'REFUNDED'; } elseif (($due_amount[$key] ?? 0) != 0 && $refunded == "Yes") { $booking_status = 'REFUND_PENDING'; } $db->table('gss_bookings') ->where('booking_id', $booking_id) ->update(['booking_status' => $booking_status]); } if (!empty($payment_data_array)) { $db->table('gss_cancellation_refunds')->insertBatch($payment_data_array); echo json_encode(['result' => 1, 'message' => 'Details added successfully']); } else { echo json_encode(['result' => 0, 'message' => 'No refund details provided']); } } else { echo json_encode(['result' => 0, 'message' => 'No details entered to update']); } } public function address_list_print() { $gss_model=new Gss_model(); $p_poject =$_GET['p_poject']; $result = $gss_model->address_list_print($p_poject); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0,'message'=>'No Details found')); } } public function add_site_image() { $gss_model = new Gss_model(); // Update namespace if necessary $db = \Config\Database::connect(); $site_id = $this->request->getPost('site_id'); $imageService = \Config\Services::image(); $file_name = ''; $file = $this->request->getFile('site_image'); if ($file && $file->isValid() && !$file->hasMoved()) { $uploadPath = FCPATH . 'project_uploads/9_and_11/'; // Create the directory if it doesn't exist if (!is_dir($uploadPath)) { mkdir($uploadPath, 0777, true); } $file_name = time() . $file->getName(); $file->move($uploadPath, $file_name); // Resize the image $imageService->withFile($uploadPath . $file_name) ->resize(200, 150, true) ->save($uploadPath . $file_name); } $updated_at = date('Y-m-d H:i:s'); $data = [ 'site_image' => $file_name, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ]; $site_table = 'gss_new_sites'; $where = ['delete_status' => 'ACTIVE', 'site_id' => $site_id]; $result = $gss_model->update1($site_table, $where, $data); // assumes you handle where conditions in `update1` if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Site image added successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong.. try again"]); } } public function update_new_site() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $table = 'gss_new_sites'; $site_id = $this->request->getpost('site_id'); $project_id = $this->request->getpost('project_id'); $site_number = $this->request->getpost('site_number'); $north_in_mtrs = $this->request->getpost('north_in_mtrs'); $south_in_mtrs = $this->request->getpost('south_in_mtrs'); $east_in_mtrs = $this->request->getpost('east_in_mtrs'); $west_in_mtrs = $this->request->getpost('west_in_mtrs'); $total_in_sqmtrs = $this->request->getpost('total_in_sqmtrs'); $total_in_sqft = $this->request->getpost('total_in_sqft'); $east_facing = $this->request->getpost('east_facing'); $west_facing = $this->request->getpost('west_facing'); $north_facing = $this->request->getpost('north_facing'); $south_facing = $this->request->getpost('south_facing'); $status = $this->request->getpost('status'); $assigned_project = $this->request->getpost('assigned_project'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); $where_file = array('site_id'=>$site_id); $site_data = $gss_model->get_where_row($table,$where_file); $data = array( 'site_number' => $site_number, 'north_in_mtrs' => $north_in_mtrs, 'south_in_mtrs' => $south_in_mtrs, 'east_in_mtrs' => $east_in_mtrs, 'west_in_mtrs' => $west_in_mtrs, 'total_in_sqmtrs' => $total_in_sqmtrs, 'total_in_sqft' => $total_in_sqft, 'east_facing' => $east_facing, 'west_facing' => $west_facing, 'north_facing' => $north_facing, 'south_facing' => $south_facing, 'status' => $status, 'assigned_project'=> $assigned_project, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ); $where_site = $site_data->site_number; $where = array( 'delete_status' => 'ACTIVE', 'site_number !=' => $where_site, 'project_id' => $project_id ); $numbers = $gss_model->get_where_result($table,$where); $array = array(); foreach($numbers as $value) { array_push($array, $value->site_number); } if(in_array($site_number,$array)) { return $this->response->setJSON(['result'=>2,'message'=>"Site number already exists in this project"]); } else { $where_id = array('site_id' => $site_id,'project_id' => $project_id); $result = $gss_model->update1($table,$where_id,$data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result'=>1,'message'=>"Updated successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Failed to update. Try again"]); } } } public function delete_conversion_order() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $table = 'gss_project_conversion_orders'; $image_id = $this->request->getpost('image_id'); $where = array('image_id'=>$image_id); $data = array('delete_status'=>'INACTIVE'); $result = $gss_model->update1($where,$table,$data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result'=>1,'message'=>'Deleted successfully']); } else { return $this->response->setJSON(['result'=>0]); } } public function get_all_reminders() { $gss_model=new Gss_model(); $result = $gss_model->get_all_reminders(); if($result) { echo json_encode(array('result'=>1,'reminders'=>$result,'total'=>count($result))); } else { echo json_encode(array('result'=>0)); } } // payment controller starts here //Payment form public function payment_form() { $session = session(); if ($session->has('admin_id')) { $GssNewProjectsModel = new GssNewProjectsModel(); $projectTable = 'gss_new_projects'; $orderBy = 'project_name'; $whereProject = ['delete_status' => 'ACTIVE', 'project_status' => 'ONGOING']; $data['projects'] = $GssNewProjectsModel->get_where_result_alphabetical($projectTable, $whereProject, $orderBy); $table = 'gss_project_master'; $where = ['delete_status' => 'ACTIVE']; $data['project'] = $GssNewProjectsModel->get_where_result_alphabetical($table, $where, 'project_name'); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/individual_payment_form', $data); } else { return redirect()->to('/'); } } //Check Booking public function check_booking() { $booking_id = $this->request->getPost('booking_id'); $result = $this->db->table('gss_bookings A') ->select('A.*, B.*, C.*, D.*') ->join('gss_new_projects B', 'B.project_id = A.project_id') ->join('gss_booking_details C', 'C.booking_id = A.booking_id') ->join('gss_booking_installments D', 'D.booking_detal_id = C.detail_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('A.booking_id', $booking_id) ->orderBy('A.booking_id', 'DESC') ->get() ->getRow(); // Fetch as object if ($result) { return $this->response->setJSON(['result' => 1, 'booking_details' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } //Add payment details public function add_payment_details() { $booking_id = $this->request->getPost('booking_id'); $detail_id = $this->request->getPost('detail_id'); $customer_name = $this->request->getPost('customer_name'); $project_id = $this->request->getPost('project_id'); $site_number = $this->request->getPost('site_number'); $site_dimension = $this->request->getPost('site_dimension'); $tsv = $this->request->getPost('tsv'); $per_sqft = $this->request->getPost('per_sqft'); $booking_date = $this->request->getPost('booking_date'); $booking_amount = $this->request->getPost('booking_amount'); $sale_agree_date = $this->request->getPost('sale_agree_date'); $sale_agree_amount = $this->request->getPost('sale_agree_amount'); $reg_due_date = $this->request->getPost('reg_due_date'); $reg_due_amount = $this->request->getPost('reg_due_amount'); $instalement_date1 = $this->request->getPost('instalement_date1'); $instalement_amount1 = $this->request->getPost('instalement_amount1'); $main_amount = $this->request->getPost('main_amount'); $no_of_years = $this->request->getPost('no_of_years'); $membership_amount = $this->request->getPost('membership_amount'); $payment_type = $this->request->getPost('payment_type'); $instalement_date2 = $this->request->getPost('instalement_date2'); $instalement_amount2 = $this->request->getPost('instalement_amount2'); $check_no = ''; $check_date = ''; $bank_name = ''; $vtr_no = ''; $online_date = ''; if ($payment_type == 'Check') { $check_no = $this->request->getPost('check_no'); $check_date = $this->request->getPost('check_date'); $bank_name = $this->request->getPost('bank_name'); } elseif ($payment_type == 'Online Payment') { $vtr_no = $this->request->getPost('vtr_no'); $online_date = $this->request->getPost('online_date'); } $date = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); // Update gss_bookings $booking_data = [ 'project_id' => $project_id, 'customer_name' => $customer_name, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ]; $this->db->table('gss_bookings') ->where('booking_id', $booking_id) ->update($booking_data); // Update gss_booking_details $detail_data = [ 'project_id' => $project_id, 'booking_date' => $booking_date, 'booking_amount' => $booking_amount, 'booking_payment_type' => $payment_type, 'check_no' => $check_no, 'check_date' => $check_date, 'bank_name' => $bank_name, 'vtr_no' => $vtr_no, 'online_date' => $online_date, 'tsv' => $tsv, 'tsv_per_sft_rs' => $per_sqft, 'sales_agreement_due_date' => $sale_agree_date, 'sales_agreement_due_amount' => $sale_agree_amount, 'registration_due_date' => $reg_due_date, 'registration_due_amount' => $reg_due_amount, 'site_number' => $site_number, 'dimension' => $site_dimension, 'maintainance_amount' => $main_amount, 'no_of_years' => $no_of_years, 'clubhouse_membership_amount' => $membership_amount, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ]; $this->db->table('gss_booking_details') ->where('booking_id', $booking_id) ->update($detail_data); if ($this->db->affectedRows() > 0) { // Check if installment exists $check_instal = $this->db->table('gss_booking_installments') ->where('booking_detal_id', $detail_id) ->get() ->getRow(); // Insert Installment 1 if ($instalement_date1 != "0000-00-00") { $instal_data1 = [ 'booking_id' => $booking_id, 'booking_detal_id' => $detail_id, 'installment_due_date' => $instalement_date1, 'installment_due_amount' => $instalement_amount1, 'payment_mode' => $payment_type ]; $this->db->table('gss_booking_installments')->insert($instal_data1); } // Insert Installment 2 if ($instalement_date2 != "0000-00-00" && $instalement_date2 != "") { $instal_data2 = [ 'booking_id' => $booking_id, 'booking_detal_id' => $detail_id, 'installment_due_date' => $instalement_date2, 'installment_due_amount' => $instalement_amount2, 'payment_mode' => $payment_type ]; $this->db->table('gss_booking_installments')->insert($instal_data2); } echo json_encode(['result' => 1, 'message' => "Updated successfully"]); } else { echo json_encode(['result' => 0, 'message' => 'Something went wrong']); } } //Payment receipt details public function payment_receipt_details() { $db = \Config\Database::connect(); $uri=service('uri'); $booking_id = $uri->getSegment(2); // 1. Site Booking Details $builder = $this->db->table('gss_bookings A'); $builder->select('A.*, B.*, C.*, D.registration_date, A.booking_status as a_booking_status, B.booking_status as b_booking_status'); $builder->join('gss_new_projects B', 'B.project_id = A.project_id'); $builder->join('gss_booking_details C', 'C.booking_id = A.booking_id'); $builder->join('gss_plot_payments D', 'D.booking_id = A.booking_id', 'left'); $builder->where('A.booking_id', $booking_id); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->orderBy('A.booking_id', 'DESC'); $site_result = $builder->get()->getRow(); $data['site_result'] = $site_result; // 2. Get Installment Row $instal_result = $this->db->table('gss_booking_installments') ->where([ 'booking_id' => $booking_id, 'delete_status' => 'ACTIVE' ]) ->get() ->getRow(); $data['instal_result'] = $instal_result; $detail_id = $instal_result->booking_detal_id ?? null; // 3. Get Project Details $get_project = $this->db->table('gss_bookings') ->where('booking_id', $booking_id) ->get() ->getRow(); $project_id = $get_project->project_id ?? null; $get_project_details = $this->db->table('gss_new_projects') ->where('project_id', $project_id) ->get() ->getRow(); $data['project'] = $get_project_details; // 4. Get Land Owner $land_owner_id = $get_project_details->land_owner_id ?? null; $get_land_owner = $this->db->table('gss_land_owners') ->where('owner_id', $land_owner_id) ->get() ->getRow(); $data['land_owner'] = $get_land_owner; // 5. Get access data (now inline, no separate method) $data['user_type_id'] = session()->get('user_type_id') ?? null; $data['access'] = session()->get('access') ?? []; // 6. Check for Payment Types $check_ids_rows = $this->db->table('gss_plot_payments A') ->select('A.*, B.*') ->join('gss_plot_payment_types B', 'B.payment_id = A.payment_id', 'left') ->where('A.booking_id', $booking_id) ->where('A.detail_id', $detail_id) ->where('A.delete_status', 'ACTIVE') ->get() ->getRow(); if ($check_ids_rows) { $data['res'] = $check_ids_rows; } else { $reg_amount = $this->db->table('gss_registration_amount_details A') ->where('A.booking_id', $booking_id) ->where('A.delete_status', 'ACTIVE') ->get() ->getRow(); $data['res'] = $reg_amount; } // 7. Load view based on land owner if (($get_land_owner->name ?? '') === 'GSS Project Consultants') { return view('admin/gss_agreement_receipt', $data); } else { return view('admin/gss_agreement_ack', $data); } } //registration reciept details public function registration_receipt_details() { // Get URI segments $booking_id = $this->request->uri->getSegment(2); $ack_no = $this->request->uri->getSegment(3); // Data array $data = []; $model = new \App\Models\GssModel(); // Fetch site booking details $data['site_result'] = $model->user_site_booking_details1($booking_id); // Get installment details $where = ['booking_id' => $booking_id, 'delete_status' => 'ACTIVE']; $data['instal_result'] = $model->get_where_row('gss_booking_installments', $where); $instal_result = $data['instal_result']; $detail_id = $instal_result ? $instal_result->booking_detal_id : null; // Fetch project details $where = ['booking_id' => $booking_id]; $get_project = $model->get_where_row('gss_bookings', $where); $project_id = $get_project->project_id; $where_project = ['project_id' => $project_id]; $get_project_details = $model->get_where_row('gss_new_projects', $where_project); $data['project'] = $get_project_details; // Fetch land owner details $land_owner = $get_project_details->land_owner_id; $where_land_owner = ['owner_id' => $land_owner]; $get_land_owner = $model->get_where_row('gss_land_owners', $where_land_owner); $data['land_owner'] = $get_land_owner; // Fetch user type and access details $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); // Fetch payment details $check_ids_rows = $model->get_payments_types($booking_id, $detail_id); $data['res'] = $check_ids_rows ?: $model->get_registration_amount($booking_id); // Fetch registration amount details $data['regs'] = $model->get_where_result('gss_registration_amount_details', ['booking_id' => $booking_id]); // Add acknowledgment number $data['ack_no'] = $ack_no; // Conditional view rendering based on land owner if ($get_land_owner->name == 'GSS Project Consultants') { return view('admin/gss_reg_receipt', $data); } else { return view('admin/gss_reg_ack', $data); } } public function individual_payment_details() { $payment_table = 'gss_plot_payments'; $type_table = 'gss_plot_payment_types'; $multireg_table = 'gss_registration_amount_details'; // Retrieve POST data using CI4's request object $model = new \App\Models\GssModel(); $booking_id = $this->request->getPost('booking_id'); $detail_id = $this->request->getPost('detail_id'); $agreement_payment_type = $this->request->getPost('agreement_payment_type'); $sale_agree_amounts = $this->request->getPost('sale_agree_amount'); $sale_agree_amount = str_replace(',', '', $sale_agree_amounts); $sale_agree_date = $this->request->getPost('sale_agree_date'); $instalment_payment_type1 = $this->request->getPost('instalment_payment_type1'); $instalement_amount1s = $this->request->getPost('instalement_amount1'); $instalement_amount1 = str_replace(',', '', $instalement_amount1s); $instal_amount = array($instalement_amount1); $installment_date1 = $this->request->getPost('installment_date1'); $regn_payment_type = $this->request->getPost('regn_payment_type'); $reg_due_amounts = $this->request->getPost('reg_due_amount'); $reg_due_amount = str_replace(',', '', $reg_due_amounts); $reg_values = $this->request->getPost('reg_value'); $reg_value = str_replace(',', '', $reg_values); $reg_status = $this->request->getPost('reg_status'); $regn_amount_type = $this->request->getPost('regn_amount_type'); $loan_from = $this->request->getPost('loan_from'); $tsvs = $this->request->getPost('tsv'); $tsv = str_replace(',', '', $tsvs); $loanregn_payment_type1 = $this->request->getPost('loanregn_payment_type1'); $loanreg_due_amounts = $this->request->getPost('loanreg_due_amount1'); $loanreg_due_amount1 = str_replace(',', '', $loanreg_due_amounts); $loanregndate1 = $this->request->getPost('loanregndate1'); $loanregn_no1 = $this->request->getPost('loanregn_no1'); $loanregn_bank1 = $this->request->getPost('loanregn_bank1'); $loanregn_amount_type = $this->request->getPost('loanregn_amount_type'); $loanloan_from = $this->request->getPost('loanloan_from'); $instalment_cheque_no1 = $this->request->getPost('instalment_cheque_no2'); $instalment_cheque_date1 = $this->request->getPost('instalment_cheque_date2'); $instalment_bank_name1 = $this->request->getPost('instalment_bank_name2'); $instalment_vtr_no11 = $this->request->getPost('instalment_vtr_no2'); $instalment_online_date11 = $this->request->getPost('instalment_online_date2'); $instalment_dd_no11 = $this->request->getPost('installment_dd_no2'); $instalment_dd_date11 = $this->request->getPost('installment_dd_date2'); $instalment_dd_bank11 = $this->request->getPost('installment_dd_bank2'); $registration1_date = $this->request->getPost('registration1_date'); $paytm_ref_no11 = $this->request->getPost('paytm_ref_no2'); $paytm_online_date11 = $this->request->getPost('paytm_online_date2'); $upi_ref_no11 = $this->request->getPost('upi_ref_no2'); $upi_online_date11 = $this->request->getPost('upi_online_date2'); $install_swipe_date2 = $this->request->getPost('install_swipe_date2'); $install_cash_date2 = $this->request->getPost('install_cash_date2'); if ($reg_status == "Date") { $registration_date = $this->request->getPost('registration_date'); if (!empty($registration_date)) { $registration_date = date('Y-m-d', strtotime($registration_date)); } } else { $registration_date = '0000-00-00'; } $main_amounts = $this->request->getPost('main_amount'); $main_amount = str_replace(',', '', $main_amounts); $no_of_years = $this->request->getPost('no_of_years'); $membership_amounts = $this->request->getPost('membership_amount'); $membership_amount = str_replace(',', '', $membership_amounts); $agreement_cheque_no = $this->request->getPost('agreement_cheque_no'); $agreement_cheque_date = $this->request->getPost('agreement_cheque_date'); if (!empty($agreement_cheque_date)) { $agreement_cheque_date = date('Y-m-d', strtotime($agreement_cheque_date)); } else { $agreement_cheque_date = ""; } $agreement_bank_name = $this->request->getPost('agreement_bank_name'); $agreement_vtr_no = $this->request->getPost('agreement_vtr_no'); $agreement_online_date = $this->request->getPost('agreement_online_date'); if (!empty($agreement_online_date) && $agreement_online_date !== "undefined-undefined-") { $agreement_online_date = date('Y-m-d', strtotime($agreement_online_date)); } else { $agreement_online_date = ""; } $agreement_dd_no = $this->request->getPost('agreement_dd_no'); $agreement_dd_date = $this->request->getPost('agreement_dd_date'); if (!empty($agreement_dd_date)) { $agreement_dd_date = date('Y-m-d', strtotime($agreement_dd_date)); } else { $agreement_dd_date = ""; } $agreement_dd_bank = $this->request->getPost('agreement_dd_bank'); $agreementpaytm_ref_no = $this->request->getPost('paytm_ref_no'); $agreementpaytm_online_date = $this->request->getPost('paytm_online_date'); $agreementupi_ref_no = $this->request->getPost('upi_ref_no'); $agreementupi_online_date = $this->request->getPost('upi_online_date'); $site_number = $this->request->getPost('site_number'); $project_id = $this->request->getPost('project_id'); $dues_option = $this->request->getPost('dues_option'); if($dues_option == 'dues') { $remarks = $this->request->getPost('remarks_added'); } else { $remarks = ""; } $agreement_confirming_type =$this->request->getPost('owners_type1'); $check_site = $model->project_details1($site_number,$project_id); if($check_site) { $site_result = $model->individual_payment_site_booking_details($site_number,$project_id,$booking_id); $tsvamount= $tsv-($site_result->booking_amount1 +$site_result->booking_amount2); if($site_result) { // print_r($site_result);die(); if($site_result->booking_status == 'CANCELLED') { echo json_encode(array('result'=>3,'message'=>'Site number '.$site_number.' has been cancelled')); } else { $regn_cheque_no = $this->request->getPost('regn_cheque_no'); $regn_cheque_date = $this->request->getPost('regn_cheque_date'); if($regn_cheque_date != "") { $regn_cheque_date = date('Y-m-d',strtotime($regn_cheque_date)); } else { $regn_cheque_date =""; } $regn_bank_name = $this->request->getPost('regn_bank_name'); $regn_vtr_no = $this->request->getPost('regn_vtr_no'); $regn_online_date = $this->request->getPost('regn_online_date'); if($regn_online_date != "") { $regn_online_date = date('Y-m-d',strtotime($regn_online_date)); } else { $regn_online_date =""; } $regn_dd_no = $this->request->getPost('regn_dd_no'); $regn_dd_date = $this->request->getPost('regn_dd_date'); if($regn_dd_date != "") { $regn_dd_date = date('Y-m-d',strtotime($regn_dd_date)); } else { $regn_dd_date =""; } $regn_dd_bank = $this->request->getPost('regn_dd_bank'); $regn_ref_no =$this->request->getPost('regn_ref_no'); $regn_paytm_date =$this->request->getPost('regn_paytm_date'); if($regn_paytm_date != "") { $regn_paytm_date = date('Y-m-d',strtotime($regn_paytm_date)); } else { $regn_paytm_date =""; } $regn_upiref_no =$this->request->getPost('regn_upiref_no'); $regn_upi_date =$this->request->getPost('regn_upi_date'); if($regn_upi_date != "") { $regn_upi_date = date('Y-m-d',strtotime($regn_upi_date)); } else { $regn_upi_date =""; } $cash_date =$this->request->getPost('cash_date'); if($cash_date != "") { $cash_date = date('Y-m-d',strtotime($cash_date)); } else { $cash_date =""; } $swipe_date =$this->request->getPost('swipe_date'); if($swipe_date != "") { $swipe_date = date('Y-m-d',strtotime($swipe_date)); } else { $swipe_date =""; } if($regn_payment_type == 'Cheque') { $reg_f_num=$this->request->getPost('regn_cheque_no'); $reg_f_bank=$this->request->getPost('regn_bank_name'); $reg_f_date=$this->request->getPost('regn_cheque_date'); } else if($regn_payment_type == 'Cash') { $reg_f_num=""; $reg_f_bank=""; $reg_f_date=$this->request->getPost('cash_date'); } else if($regn_payment_type == 'DD') { $reg_f_num=$this->request->getPost('regn_dd_no'); $reg_f_bank=$this->request->getPost('regn_dd_bank'); $reg_f_date=$this->request->getPost('regn_dd_bank'); } else if($regn_payment_type == 'Online Payment') { $reg_f_num=$this->request->getPost('regn_vtr_no'); $reg_f_bank=""; $reg_f_date=$this->request->getPost('regn_online_date'); } else if($regn_payment_type == 'Paytm Payment') { $reg_f_num=$this->request->getPost('regn_ref_no'); $reg_f_bank=""; $reg_f_date=$this->request->getPost('regn_paytm_date'); } else if($regn_payment_type == 'UPI Payment') { $reg_f_num=$this->request->getPost('regn_upiref_no'); $reg_f_bank=""; $reg_f_date=$this->request->getPost('regn_upi_date'); } else if($regn_payment_type == 'Swipe') { $reg_f_num=""; $reg_f_bank=""; $reg_f_date=$this->request->getPost('swipe_date'); } else { $reg_f_num=""; $reg_f_bank=""; $reg_f_date=""; } $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $where1 = ['booking_id' => $booking_id, 'detail_id' => $detail_id, 'delete_status' => 'ACTIVE']; $check_ids = $model->get_where_payment_id_result($payment_table, $where1); $whereloan1 = ['booking_id' => $booking_id, 'detail_id' => $detail_id, 'delete_status' => 'ACTIVE']; $check_idsloan = $model->get_where_multireg_id_result($multireg_table, $whereloan1); $notifications = $model->check_notification($booking_id, $detail_id); $booking_table = 'gss_bookings'; $where_booking = ['booking_id' => $booking_id]; $notification_table = 'gss_commission_notifications'; if($notifications) { if($notifications->commission_agreement == "Not Available" && $sale_agree_amount != "") { $commission_agreement = 'Available'; $notification_data = [ 'booking_id' => $booking_id, 'commission_agreement' => $commission_agreement ]; $update = $model->update($where_booking, $notification_table, $notification_data); } if($notifications->commission_registration == "Not Available" && $reg_due_amount != "") { $commission_registration = 'Available'; $notification_data = [ 'booking_id' => $booking_id, 'commission_registration' => $commission_registration ]; $update = $model->update($where_booking, $notification_table, $notification_data); } } else { if($sale_agree_amount != "") { $commission_agreement = 'Available'; } else { $commission_agreement = "Not Available"; } if($reg_due_amount != "") { $commission_registration = 'Available'; } else { $commission_registration = "Not Available"; } $notification_data = [ 'booking_id' => $booking_id, 'detail_id' => $detail_id, 'commission_agreement' => $commission_agreement, 'commission_registration' => $commission_registration, 'status' => 'PENDING' ]; $check_associate = $model->get_where_row($booking_table, $where_booking); if($check_associate->associate != 0) { $commission_result = $model->insert($notification_table, $notification_data); } } //---------------------------------------------- if($check_ids) { $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $total = 0; $arr = []; foreach ($instalement_amount1 as $key => $value) { if (empty($value)) { unset($instalement_amount1[$key]); } } foreach ($instalment_payment_type1 as $key => $value) { if ($value == '0') { unset($instalment_payment_type1[$key]); } } $up_res_id = 0; if (!empty($instalement_amount1)) { $instal_amt = array_sum($instalement_amount1); } else { $instal_amt = 0; } if (!empty($loanreg_due_amount1)) { $reg_amt = array_sum($loanreg_due_amount1); } else { $reg_amt = 0; } if ($sale_agree_amount != "" && $reg_due_amount != "") { $total = $sale_agree_amount + $instal_amt + $reg_due_amount + $reg_amt; } else if ($sale_agree_amount != "" && $reg_due_amount == "") { $reg_due_amount = 0; $total = $sale_agree_amount + $instal_amt + $reg_due_amount + $reg_amt; } else if ($sale_agree_amount == "" && $reg_due_amount != "") { $sale_agree_amount = 0; $total = $sale_agree_amount + $instal_amt + $reg_due_amount + $reg_amt; } if($total > $tsvamount) { echo json_encode(['result' => 3, 'message' => "Not matching TSV"]); } else { foreach($check_ids as $id) { $deletetable = 'gss_plot_payment_types'; $deletewhere = ['payment_id' => $id->payment_id]; $drop = $model->delete($deletetable, $deletewhere); $deletetable1 = 'gss_plot_payments'; $deletewhere1 = ['payment_id' => $id->payment_id]; $model->delete($deletetable1, $deletewhere1); } $data10 = []; if (!empty($instalement_amount1)) { foreach ($instalement_amount1 as $key => $val) { $installment_confirming_type = $this->request->getPost('installment_confirming_type' . $key); //$registration_confirming_type = $this->request->getPost('registration_confirming_types' . $key); $registration_confirming_type = $this->request->getPost('registration_confirming_type'); $payment_data = [ 'booking_id' => $booking_id, 'detail_id' => $detail_id, 'agreement_amount' => $sale_agree_amount, 'agreement_date' => $sale_agree_date, 'agreement_payment_mode' => $agreement_payment_type, 'agreement_confirming_type' => $agreement_confirming_type, 'installment_amount1' => $instalement_amount1[$key], 'installment_payment_mode1' => $instalment_payment_type1[$key], 'installment1_date' => $installment_date1[$key], 'installment_confirming_type' => $installment_confirming_type, 'registration_amount' => $reg_due_amount, 'registration_value' => $reg_value, 'regn_amount_type' => $regn_amount_type, 'loan_from' => $loan_from, 'registration_date' => $registration_date, 'registration_payment_mode' => $regn_payment_type, 'registration_status' => $reg_status, 'registration_confirming_type' => $registration_confirming_type, //'registration_done_date' => $registration1_date, 'reg_f_num' => $reg_f_num, 'reg_f_bank' => $reg_f_bank, 'reg_f_date' => $reg_f_date, 'membership_amount' => $membership_amount, 'maintenence_amount' => $main_amount, 'no_of_years' => $no_of_years, 'dues_option' => $dues_option, 'remarks' => $remarks, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $result = $model->insert($payment_table, $payment_data); array_push($data10, $result); } } else { $registration_confirming_type = $this->request->getPost('registration_confirming_type'); $payment_data = [ 'booking_id' => $booking_id, 'detail_id' => $detail_id, 'agreement_amount' => $sale_agree_amount, 'agreement_date' => $sale_agree_date, 'agreement_payment_mode' => $agreement_payment_type, 'agreement_confirming_type' => $agreement_confirming_type, 'installment_amount1' => '', 'installment_payment_mode1' => '', 'installment1_date' => '', 'registration_amount' => $reg_due_amount, 'registration_value' => $reg_value, 'regn_amount_type' => $regn_amount_type, 'loan_from' => $loan_from, 'registration_date' => $registration_date, 'registration_payment_mode' => $regn_payment_type, 'registration_status' => $reg_status, 'registration_confirming_type' => $registration_confirming_type, //'registration_done_date' => $registration1_date, 'reg_f_num' => $reg_f_num, 'reg_f_bank' => $reg_f_bank, 'reg_f_date' => $reg_f_date, 'membership_amount' => $membership_amount, 'maintenence_amount' => $main_amount, 'no_of_years' => $no_of_years, 'dues_option' => $dues_option, 'remarks' => $remarks, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $res_id = $model->insert($payment_table, $payment_data); } $data9 = []; if (!empty($instalement_amount1)) { foreach ($instalement_amount1 as $key => $val) { $payment_type = $instalment_payment_type1[$key]; $type_dataa = [ 'install_cheque_no1' => '', 'install_cheque_date1' => '', 'install_bank1' => '', 'install_vtr_no1' => '', 'install_online_date1' => '', 'install_dd_no1' => '', 'install_dd_date1' => '', 'install_dd_bank1' => '', 'paytm_ref_no' => '', 'paytm_online_date1' => '', 'upi_ref_no' => '', 'upi_online_date1' => '', 'install_cash_date' => '', 'install_swipe_date' => '', 'payment_id' => $data10[$key] ]; // Conditional overwrite based on payment type if ($payment_type == 'Cheque') { $type_dataa['install_cheque_no1'] = $this->request->getPost('instalment_cheque_no2' . $key); $type_dataa['install_cheque_date1'] = $this->request->getPost('instalment_cheque_date2' . $key); $type_dataa['install_bank1'] = $this->request->getPost('instalment_bank_name2' . $key); } elseif ($payment_type == 'Online Payment') { $type_dataa['install_vtr_no1'] = $this->request->getPost('instalment_vtr_no2' . $key); $type_dataa['install_online_date1'] = $this->request->getPost('instalment_online_date2' . $key); } elseif ($payment_type == 'DD') { $type_dataa['install_dd_no1'] = $this->request->getPost('installment_dd_no2' . $key); $type_dataa['install_dd_date1'] = $this->request->getPost('installment_dd_date2' . $key); $type_dataa['install_dd_bank1'] = $this->request->getPost('installment_dd_bank2' . $key); } elseif ($payment_type == 'Paytm Payment') { $type_dataa['paytm_ref_no'] = $this->request->getPost('paytm_ref_no2' . $key); $type_dataa['paytm_online_date1'] = $this->request->getPost('paytm_online_date2' . $key); } elseif ($payment_type == 'UPI Payment') { $type_dataa['upi_ref_no'] = $this->request->getPost('upi_ref_no2' . $key); $type_dataa['upi_online_date1'] = $this->request->getPost('upi_online_date2' . $key); } elseif ($payment_type == 'Cash') { $type_dataa['install_cash_date'] = $this->request->getPost('install_cash_date2' . $key); } elseif ($payment_type == 'Swipe') { $type_dataa['install_swipe_date'] = $this->request->getPost('install_swipe_date2' . $key); } $type_table = 'gss_plot_payment_types'; $resulttt = $model->insert($type_table, $type_dataa); array_push($data9, $resulttt); } } else if ($agreement_payment_type != '0') { if ($agreement_payment_type == 'Cheque') { $type_data = [ 'agreement_cheque_no' => $agreement_cheque_no, 'agreement_cheque_date' => $agreement_cheque_date, 'agreement_bank' => $agreement_bank_name, 'agreement_vtr_no' => '', 'agreement_online_date' => '', 'agreement_dd_no' => '', 'agreement_dd_date' => '', 'agreement_dd_bank' => '', 'agreementpaytm_ref_no' => '', 'agreementpaytm_online_date1' => '', 'agreementupi_ref_no' => '', 'agreementupi_online_date1' => '', 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; } else if ($agreement_payment_type == 'Online Payment') { $type_data = [ 'agreement_cheque_no' => '', 'agreement_cheque_date' => '', 'agreement_bank' => '', 'agreement_vtr_no' => $agreement_vtr_no, 'agreement_online_date' => $agreement_online_date, 'agreement_dd_no' => '', 'agreement_dd_date' => '', 'agreement_dd_bank' => '', 'agreementpaytm_ref_no' => '', 'agreementpaytm_online_date1' => '', 'agreementupi_ref_no' => '', 'agreementupi_online_date1' => '', 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; } else if ($agreement_payment_type == 'DD') { $type_data = [ 'agreement_cheque_no' => '', 'agreement_cheque_date' => '', 'agreement_bank' => '', 'agreement_vtr_no' => '', 'agreement_online_date' => '', 'agreement_dd_no' => $agreement_dd_no, 'agreement_dd_date' => $agreement_dd_date, 'agreement_dd_bank' => $agreement_dd_bank, 'agreementpaytm_ref_no' => '', 'agreementpaytm_online_date1' => '', 'agreementupi_ref_no' => '', 'agreementupi_online_date1' => '', 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; } else if ($agreement_payment_type == 'Paytm Payment') { $type_data = [ 'agreement_cheque_no' => '', 'agreement_cheque_date' => '', 'agreement_bank' => '', 'agreement_vtr_no' => '', 'agreement_online_date' => '', 'agreement_dd_no' => '', 'agreement_dd_date' => '', 'agreement_dd_bank' => '', 'agreementpaytm_ref_no' => $agreementpaytm_ref_no, 'agreementpaytm_online_date1' => $agreementpaytm_online_date, 'agreementupi_ref_no' => '', 'agreementupi_online_date1' => '', 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; } else if ($agreement_payment_type == 'UPI Payment') { $type_data = [ 'agreement_cheque_no' => '', 'agreement_cheque_date' => '', 'agreement_bank' => '', 'agreement_vtr_no' => '', 'agreement_online_date' => '', 'agreement_dd_no' => '', 'agreement_dd_date' => '', 'agreement_dd_bank' => '', 'agreementpaytm_ref_no' => '', 'agreementpaytm_online_date1' => '', 'agreementupi_ref_no' => $agreementupi_ref_no, 'agreementupi_online_date1' => $agreementupi_online_date, 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; } else if ($agreement_payment_type == 'Cash') { $type_data = [ 'agreement_cheque_no' => '', 'agreement_cheque_date' => '', 'agreement_bank' => '', 'agreement_vtr_no' => '', 'agreement_online_date' => '', 'agreement_dd_no' => '', 'agreement_dd_date' => '', 'agreement_dd_bank' => '', 'agreementpaytm_ref_no' => '', 'agreementpaytm_online_date1' => '', 'agreementupi_ref_no' => '', 'agreementupi_online_date1' => '', 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; $model = new \App\Models\GssModel(); $up_res_id = $model->insert($type_data); // gss_plot_payment_types should be the table name defined in model } $type_table = 'gss_plot_payment_types'; $up_res_id = $model->insert($type_table, $type_data); } else { $type_data = [ 'agreement_cheque_no' => '', 'agreement_cheque_date' => '', 'agreement_bank' => '', 'agreement_vtr_no' => '', 'agreement_online_date' => '', 'agreement_dd_no' => '', 'agreement_dd_date' => '', 'agreement_dd_bank' => '', 'agreementpaytm_ref_no' => '', 'agreementpaytm_online_date1' => '', 'agreementupi_ref_no' => '', 'agreementupi_online_date1' => '', 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; // CI4 way $model = new \App\Models\GssModel(); $up_res_id = $model->insert($type_data); } if (!empty($instalment_payment_type1)) { foreach ($instalment_payment_type1 as $key => $val) { $type_data = [ 'payment_id' => $data10[$key], 'agreement_cheque_no' => $agreement_cheque_no, 'agreement_cheque_date' => $agreement_cheque_date, 'agreement_bank' => $agreement_bank_name, 'agreement_vtr_no' => $agreement_vtr_no, 'agreement_online_date' => $agreement_online_date, 'agreement_dd_no' => $agreement_dd_no, 'agreement_dd_date' => $agreement_dd_date, 'agreement_dd_bank' => $agreement_dd_bank, 'agreementpaytm_ref_no' => $agreementpaytm_ref_no, 'agreementpaytm_online_date1' => $agreementpaytm_online_date, 'agreementupi_ref_no' => $agreementupi_ref_no, 'agreementupi_online_date1' => $agreementupi_online_date, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ]; $model->update($data9[$key], $type_data); } } else { $type_data = [ 'payment_id' => $res_id, 'agreement_cheque_no' => $agreement_cheque_no, 'agreement_cheque_date' => $agreement_cheque_date, 'agreement_bank' => $agreement_bank_name, 'agreement_vtr_no' => $agreement_vtr_no, 'agreement_online_date' => $agreement_online_date, 'agreement_dd_no' => $agreement_dd_no, 'agreement_dd_date' => $agreement_dd_date, 'agreement_dd_bank' => $agreement_dd_bank, 'agreementpaytm_ref_no' => $agreementpaytm_ref_no, 'agreementpaytm_online_date1' => $agreementpaytm_online_date, 'agreementupi_ref_no' => $agreementupi_ref_no, 'agreementupi_online_date1' => $agreementupi_online_date, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ]; $model->update($up_res_id, $type_data); } if ($check_idsloan) { foreach ($check_idsloan as $ids) { $model->where('id', $ids->id)->delete('gss_registration_amount_details'); } if ($loanreg_due_amount1 != "") { foreach ($loanreg_due_amount1 as $key => $val) { $registration_confirming_types = $this->request->getPost('registration_confirming_types'); $multireg_data = [ 'booking_id' => $booking_id, 'detail_id' => $detail_id, 'reg_amount' => $loanreg_due_amount1[$key], 'reg_payment_mode' => $loanregn_payment_type1[$key], 'number' => $loanregn_no1[$key], 'mode_date' => $loanregndate1[$key], 'branch_name' => $loanregn_bank1[$key], 'loan_type' => $loanregn_amount_type[$key], 'loan_from' => $loanloan_from[$key], 'registration_confirming_type' => $registration_confirming_types[$key], 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $model->insert($multireg_data); } } } else { if ($loanreg_due_amount1 != "") { foreach ($loanreg_due_amount1 as $key => $val) { $registration_confirming_types = $this->request->getPost('registration_confirming_types'); $multireg_data = [ 'booking_id' => $booking_id, 'detail_id' => $detail_id, 'reg_amount' => $loanreg_due_amount1[$key], 'reg_payment_mode' => $loanregn_payment_type1[$key], 'number' => $loanregn_no1[$key], 'mode_date' => $loanregndate1[$key], 'branch_name' => $loanregn_bank1[$key], 'loan_type' => $loanregn_amount_type[$key], 'loan_from' => $loanloan_from[$key], 'registration_confirming_type' => $registration_confirming_types[$key], 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $model->insert($multireg_data); } } } echo json_encode(['result' => 1, 'message' => " successfully Updated"]); } } else { $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $total = 0; $arr = []; if (!empty($instalement_amount1)) { $instal_amt = array_sum($instalement_amount1); } else { $instal_amt = 0; } if (!empty($loanreg_due_amount1)) { $reg_amt = array_sum($loanreg_due_amount1); } else { $reg_amt = 0; } if ($sale_agree_amount != "" && $reg_due_amount != "") { $total = $sale_agree_amount + $instal_amt + $reg_due_amount + $reg_amt; } else if ($sale_agree_amount != "" && $reg_due_amount == "") { $reg_due_amount = 0; $total = $sale_agree_amount + $instal_amt + $reg_due_amount + $reg_amt; } else if ($sale_agree_amount == "" && $reg_due_amount != "") { $sale_agree_amount = 0; $total = $sale_agree_amount + $instal_amt + $reg_due_amount + $reg_amt; } if ($total > $tsvamount) { echo json_encode(['result' => 3, 'message' => "Not matching TSV"]); } else { $data10 = []; if (!empty($instalement_amount1)) { foreach ($instalement_amount1 as $key => $val) { $installment_confirming_type = $this->request->getPost('installment_confirming_type' . $key); $registration_confirming_type = $this->request->getPost('registration_confirming_type'); $payment_data = [ 'booking_id' => $booking_id, 'detail_id' => $detail_id, 'agreement_amount' => $sale_agree_amount, 'agreement_date' => $sale_agree_date, 'agreement_payment_mode' => $agreement_payment_type, 'agreement_confirming_type' => $agreement_confirming_type, 'installment_amount1' => $instalement_amount1[$key], 'installment_payment_mode1' => $instalment_payment_type1[$key], 'installment1_date' => $installment_date1[$key], 'installment_confirming_type' => $installment_confirming_type, 'registration_amount' => $reg_due_amount, 'registration_value' => $reg_value, 'regn_amount_type' => $regn_amount_type, 'loan_from' => $loan_from, 'registration_date' => $registration_date, 'registration_payment_mode' => $regn_payment_type, 'registration_status' => $reg_status, 'registration_confirming_type' => $registration_confirming_type, 'reg_f_num' => $reg_f_num, 'reg_f_bank' => $reg_f_bank, 'reg_f_date' => $reg_f_date, 'membership_amount' => $membership_amount, 'maintenence_amount' => $main_amount, 'no_of_years' => $no_of_years, 'delete_status' => 'ACTIVE', 'dues_option' => $dues_option, 'remarks' => $remarks, 'created_at' => $created_at ]; $result = $model->insert($payment_table, $payment_data); $data10[] = $result; } } else { $registration_confirming_type = $this->request->getPost('registration_confirming_type'); $payment_data = [ 'booking_id' => $booking_id, 'detail_id' => $detail_id, 'agreement_amount' => $sale_agree_amount, 'agreement_date' => $sale_agree_date, 'agreement_payment_mode' => $agreement_payment_type, 'agreement_confirming_type' => $agreement_confirming_type, 'installment_amount1' => '', 'installment_payment_mode1' => '', 'installment1_date' => '', 'installment_confirming_type' => '', 'registration_amount' => $reg_due_amount, 'registration_value' => $reg_value, 'regn_amount_type' => $regn_amount_type, 'loan_from' => $loan_from, 'registration_date' => $registration_date, 'registration_payment_mode' => $regn_payment_type, 'registration_status' => $reg_status, 'registration_confirming_type' => $registration_confirming_type, // 'registration_done_date' => $registration1_date, // commented as per original 'reg_f_num' => $reg_f_num, 'reg_f_bank' => $reg_f_bank, 'reg_f_date' => $reg_f_date, 'membership_amount' => $membership_amount, 'maintenence_amount' => $main_amount, 'no_of_years' => $no_of_years, 'delete_status' => 'ACTIVE', 'dues_option' => $dues_option, 'remarks' => $remarks, 'created_at' => $created_at ]; $res_id = $model->insert($payment_table, $payment_data); } $data9 = []; if (!empty($instalement_amount1)) { foreach ($instalement_amount1 as $key => $val) { if ($instalment_payment_type1[$key] == 'Cheque') { $installment_cheque_no = $this->request->getPost('instalment_cheque_no2' . $key); $installment_cheque_date = $this->request->getPost('instalment_cheque_date2' . $key); $instalment_bank_name = $this->request->getPost('instalment_bank_name2' . $key); $type_dataa = [ 'install_cheque_no1' => $installment_cheque_no, 'install_cheque_date1' => $installment_cheque_date, 'install_bank1' => $instalment_bank_name, 'install_vtr_no1' => '', 'install_online_date1' => '', 'install_dd_no1' => '', 'install_dd_date1' => '', 'install_dd_bank1' => '', 'paytm_ref_no' => '', 'paytm_online_date1' => '', 'upi_ref_no' => '', 'upi_online_date1' => '', 'install_cash_date' => '', 'install_swipe_date' => '', 'payment_id' => $data10[$key], ]; $type_table = 'gss_plot_payment_types'; $resulttt = $model->insert($type_table, $type_dataa); array_push($data9, $resulttt); } else if ($instalment_payment_type1[$key] == 'Online Payment') { $installment_vtr_no = $this->request->getPost('instalment_vtr_no2' . $key); $installment_online_date = $this->request->getPost('instalment_online_date2' . $key); $type_dataa = [ 'install_cheque_no1' => '', 'install_cheque_date1' => '', 'install_bank1' => '', 'install_vtr_no1' => $installment_vtr_no, 'install_online_date1' => $installment_online_date, 'install_dd_no1' => '', 'install_dd_date1' => '', 'install_dd_bank1' => '', 'paytm_ref_no' => '', 'paytm_online_date1' => '', 'upi_ref_no' => '', 'upi_online_date1' => '', 'install_cash_date' => '', 'install_swipe_date' => '', 'payment_id' => $data10[$key], ]; $type_table = 'gss_plot_payment_types'; $resulttt = $model->insert($type_table, $type_dataa); array_push($data9, $resulttt); } else if ($instalment_payment_type1[$key] == 'DD') { $installment_dd_no = $this->request->getPost('installment_dd_no2' . $key); $installment_dd_date = $this->request->getPost('installment_dd_date2' . $key); $installment_dd_bank = $this->request->getPost('installment_dd_bank2' . $key); $type_dataa = [ 'install_cheque_no1' => '', 'install_cheque_date1' => '', 'install_bank1' => '', 'install_vtr_no1' => '', 'install_online_date1' => '', 'install_dd_no1' => $installment_dd_no, 'install_dd_date1' => $installment_dd_date, 'install_dd_bank1' => $installment_dd_bank, 'paytm_ref_no' => '', 'paytm_online_date1' => '', 'upi_ref_no' => '', 'upi_online_date1' => '', 'install_cash_date' => '', 'install_swipe_date' => '', 'payment_id' => $data10[$key], ]; $type_table = 'gss_plot_payment_types'; $resulttt = $model->insert($type_table, $type_dataa); array_push($data9, $resulttt); } else if($instalment_payment_type1[$key] == 'Paytm Payment') { $paytm_ref_no = $this->request->getPost('paytm_ref_no2' . $key); $paytm_online_date = $this->request->getPost('paytm_online_date2' . $key); $type_dataa = array( 'install_cheque_no1' => '', 'install_cheque_date1' => '', 'install_bank1' => '', 'install_vtr_no1' => '', 'install_online_date1' => '', 'install_dd_no1' => '', 'install_dd_date1' => '', 'install_dd_bank1' => '', 'paytm_ref_no' => $paytm_ref_no, 'paytm_online_date1' => $paytm_online_date, 'upi_ref_no' => '', 'upi_online_date1' => '', 'install_cash_date' => '', 'install_swipe_date' => '', 'payment_id' => $data10[$key], ); $type_table = 'gss_plot_payment_types'; $resulttt = $model->insert($type_table, $type_dataa); array_push($data9, $resulttt); } else if ($instalment_payment_type1[$key] == 'UPI Payment') { $upi_ref_no = $this->request->getPost('upi_ref_no2' . $key); $upi_online_date = $this->request->getPost('upi_online_date2' . $key); $type_dataa = [ 'install_cheque_no1' => '', 'install_cheque_date1' => '', 'install_bank1' => '', 'install_vtr_no1' => '', 'install_online_date1' => '', 'install_dd_no1' => '', 'install_dd_date1' => '', 'install_dd_bank1' => '', 'paytm_ref_no' => '', 'paytm_online_date1' => '', 'upi_ref_no' => $upi_ref_no, 'upi_online_date1' => $upi_online_date, 'install_cash_date' => '', 'install_swipe_date' => '', 'payment_id' => $data10[$key], ]; $type_table = 'gss_plot_payment_types'; $resulttt = $model->insert($type_table, $type_dataa); array_push($data9, $resulttt); } else if ($instalment_payment_type1[$key] == 'Cash') { $install_cash_date2 = $this->request->getPost('install_cash_date2' . $key); $type_dataa = [ 'install_cheque_no1' => '', 'install_cheque_date1' => '', 'install_bank1' => '', 'install_vtr_no1' => '', 'install_online_date1' => '', 'install_dd_no1' => '', 'install_dd_date1' => '', 'install_dd_bank1' => '', 'paytm_ref_no' => '', 'paytm_online_date1' => '', 'upi_ref_no' => '', 'upi_online_date1' => '', 'install_cash_date' => $install_cash_date2, 'install_swipe_date' => '', 'payment_id' => $data10[$key], ]; $type_table = 'gss_plot_payment_types'; $resulttt = $model->insert($type_table, $type_dataa); array_push($data9, $resulttt); } else if ($instalment_payment_type1[$key] == 'Swipe') { $install_swipe_date2 = $this->request->getPost('install_swipe_date2' . $key); $type_dataa = [ 'install_cheque_no1' => '', 'install_cheque_date1' => '', 'install_bank1' => '', 'install_vtr_no1' => '', 'install_online_date1' => '', 'install_dd_no1' => '', 'install_dd_date1' => '', 'install_dd_bank1' => '', 'paytm_ref_no' => '', 'paytm_online_date1' => '', 'upi_ref_no' => '', 'upi_online_date1' => '', 'install_cash_date' => '', 'install_swipe_date' => $install_swipe_date2, 'payment_id' => $data10[$key], ]; $type_table = 'gss_plot_payment_types'; $resulttt = $model->insert($type_table, $type_dataa); array_push($data9, $resulttt); } else { $type_dataa = [ 'install_cheque_no1' => '', 'install_cheque_date1' => '', 'install_bank1' => '', 'install_vtr_no1' => '', 'install_online_date1' => '', 'install_dd_no1' => '', 'install_dd_date1' => '', 'install_dd_bank1' => '', 'paytm_ref_no' => '', 'paytm_online_date1' => '', 'upi_ref_no' => '', 'upi_online_date1' => '', 'install_cash_date' => '', 'install_swipe_date' => '', 'payment_id' => $data10[$key], ]; $type_table = 'gss_plot_payment_types'; $resulttt = $model->insert($type_table, $type_dataa); array_push($data9, $resulttt); } } } else { if ($agreement_payment_type == 'Cheque') { $type_data = [ 'agreement_cheque_no' => $agreement_cheque_no, 'agreement_cheque_date' => $agreement_cheque_date, 'agreement_bank' => $agreement_bank_name, 'agreement_vtr_no' => '', 'agreement_online_date' => '', 'agreement_dd_no' => '', 'agreement_dd_date' => '', 'agreement_dd_bank' => '', 'agreementpaytm_ref_no' => '', 'agreementpaytm_online_date1' => '', 'agreementupi_ref_no' => '', 'agreementupi_online_date1' => '', 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, // varu 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; } else if ($agreement_payment_type == 'Online Payment') { $type_data = [ 'agreement_cheque_no' => '', 'agreement_cheque_date' => '', 'agreement_bank' => '', 'agreement_vtr_no' => $agreement_vtr_no, 'agreement_online_date' => $agreement_online_date, 'agreement_dd_no' => '', 'agreement_dd_date' => '', 'agreement_dd_bank' => '', 'agreementpaytm_ref_no' => '', 'agreementpaytm_online_date1' => '', 'agreementupi_ref_no' => '', 'agreementupi_online_date1' => '', 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, // varu 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; } else if ($agreement_payment_type == 'DD') { $type_data = [ 'agreement_cheque_no' => '', 'agreement_cheque_date' => '', 'agreement_bank' => '', 'agreement_vtr_no' => '', 'agreement_online_date' => '', 'agreement_dd_no' => $agreement_dd_no, 'agreement_dd_date' => $agreement_dd_date, 'agreement_dd_bank' => $agreement_dd_bank, 'agreementpaytm_ref_no' => '', 'agreementpaytm_online_date1' => '', 'agreementupi_ref_no' => '', 'agreementupi_online_date1' => '', 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, // varu 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; } else if ($agreement_payment_type == 'Paytm Payment') { $type_data = [ 'agreement_cheque_no' => '', 'agreement_cheque_date' => '', 'agreement_bank' => '', 'agreement_vtr_no' => '', 'agreement_online_date' => '', 'agreement_dd_no' => '', 'agreement_dd_date' => '', 'agreement_dd_bank' => '', 'agreementpaytm_ref_no' => $agreementpaytm_ref_no, 'agreementpaytm_online_date1' => $agreementpaytm_online_date, 'agreementupi_ref_no' => '', 'agreementupi_online_date1' => '', 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, // varu 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; } else if ($agreement_payment_type == 'UPI Payment') { $type_data = [ 'agreement_cheque_no' => '', 'agreement_cheque_date' => '', 'agreement_bank' => '', 'agreement_vtr_no' => '', 'agreement_online_date' => '', 'agreement_dd_no' => '', 'agreement_dd_date' => '', 'agreement_dd_bank' => '', 'agreementpaytm_ref_no' => '', 'agreementpaytm_online_date1' => '', 'agreementupi_ref_no' => $agreementupi_ref_no, 'agreementupi_online_date1' => $agreementupi_online_date, 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, // varu 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; } else if ($agreement_payment_type == 'Cash') { $type_data = [ 'agreement_cheque_no' => '', 'agreement_cheque_date' => '', 'agreement_bank' => '', 'agreement_vtr_no' => '', 'agreement_online_date' => '', 'agreement_dd_no' => '', 'agreement_dd_date' => '', 'agreement_dd_bank' => '', 'agreementpaytm_ref_no' => '', 'agreementpaytm_online_date1' => '', 'agreementupi_ref_no' => '', 'agreementupi_online_date1' => '', 'payment_id' => $res_id, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, // varu 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, ]; } $type_table = 'gss_plot_payment_types'; $up_res_id = $model->insert($type_data); // CI4 doesn't require passing the table name if model is set } if ($instalment_payment_type1 != "") { foreach ($instalment_payment_type1 as $key => $val) { $type_data = [ 'payment_id' => $data10[$key], 'agreement_cheque_no' => $agreement_cheque_no, 'agreement_cheque_date' => $agreement_cheque_date, 'agreement_bank' => $agreement_bank_name, 'agreement_vtr_no' => $agreement_vtr_no, 'agreement_online_date' => $agreement_online_date, 'agreement_dd_no' => $agreement_dd_no, 'agreement_dd_date' => $agreement_dd_date, 'agreement_dd_bank' => $agreement_dd_bank, 'agreementpaytm_ref_no' => $agreementpaytm_ref_no, 'agreementpaytm_online_date1' => $agreementpaytm_online_date, 'agreementupi_ref_no' => $agreementupi_ref_no, 'agreementupi_online_date1' => $agreementupi_online_date, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ]; $model ->where('type_id', $data9[$key]) ->set($type_data) ->update(); } } else { $type_data = [ 'payment_id' => $res_id, 'agreement_cheque_no' => $agreement_cheque_no, 'agreement_cheque_date' => $agreement_cheque_date, 'agreement_bank' => $agreement_bank_name, 'agreement_vtr_no' => $agreement_vtr_no, 'agreement_online_date' => $agreement_online_date, 'agreement_dd_no' => $agreement_dd_no, 'agreement_dd_date' => $agreement_dd_date, 'agreement_dd_bank' => $agreement_dd_bank, 'agreementpaytm_ref_no' => $agreementpaytm_ref_no, 'agreementpaytm_online_date1' => $agreementpaytm_online_date, 'agreementupi_ref_no' => $agreementupi_ref_no, 'agreementupi_online_date1' => $agreementupi_online_date, 'regn_cheque_no' => $regn_cheque_no, 'regn_cheque_date' => $regn_cheque_date, 'regn_bank' => $regn_bank_name, 'regn_vtr_no' => $regn_vtr_no, 'regn_online_date' => $regn_online_date, 'regn_dd_no' => $regn_dd_no, 'regn_dd_date' => $regn_dd_date, 'regn_dd_bank' => $regn_dd_bank, 'regn_ref_no' => $regn_ref_no, 'regn_paytm_date' => $regn_paytm_date, 'regn_upiref_no' => $regn_upiref_no, 'regn_upi_date' => $regn_upi_date, 'cash_date' => $cash_date, 'swipe_date' => $swipe_date, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ]; $model ->where('type_id', $up_res_id) ->set($type_data) ->update(); } if ($loanreg_due_amount1 != "") { foreach ($loanreg_due_amount1 as $key => $val) { $registration_confirming_types = $this->request->getPost('registration_confirming_types'); $multireg_data = [ 'booking_id' => $booking_id, 'detail_id' => $detail_id, 'reg_amount' => $loanreg_due_amount1[$key], // 'reg_date' => $loanreg_status1[$key], 'reg_payment_mode' => $loanregn_payment_type1[$key], // fixed backtick typo 'number' => $loanregn_no1[$key], 'mode_date' => $loanregndate1[$key], 'branch_name' => $loanregn_bank1[$key], 'loan_type' => $loanregn_amount_type[$key], 'loan_from' => $loanloan_from[$key], 'registration_confirming_type' => $registration_confirming_types[$key], 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $result = $model->insert($multireg_table, $multireg_data); } } return $this->response->setJSON(['result' => 1, 'message' => 'Successfully Added']); } } } } else { return $this->response->setJSON([ 'result' => 0, 'message' => 'Site number ' . $site_number . ' not booked' ]); } } else { return $this->response->setJSON([ 'result' => 2, 'message' => 'Site number ' . $site_number . ' not found' ]); } } public function delete_installation() { $payment_id = $this->request->getPost('payment_id'); if (!$payment_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid Payment ID']); } $db = \Config\Database::connect(); $builder = $db->table('gss_plot_payments'); // 1. Get the current record $type_result = $builder->where([ 'payment_id' => $payment_id, 'install_delete_status' => 'ACTIVE' ])->get()->getRow(); if ($type_result && $type_result->installment_amount1 != "") { // 2. Update install_delete_status to INACTIVE $updated = $builder->where('payment_id', $payment_id) ->update(['install_delete_status' => 'INACTIVE']); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No changes made']); } } else { return $this->response->setJSON(['result' => 0, 'message' => 'Installment not found or already inactive']); } } public function delete_registration() { $payment_id = $this->request->getPost('payment_id'); $booking_id = $this->request->getPost('booking_id'); if (!$booking_id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid booking ID']); } $db = \Config\Database::connect(); $builder = $db->table('gss_plot_payments'); $where_booking = [ 'booking_id' => $booking_id, 'registration_delete_status' => 'ACTIVE' ]; $update_status = [ 'registration_delete_status' => 'INACTIVE' ]; $builder->where($where_booking)->update($update_status); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No changes made']); } } public function delete_agreements() { $payment_id = $this->request->getPost('payment_id'); $booking_id = $this->request->getPost('booking_id'); if (!$booking_id) { return $this->response->setJSON([ 'result' => 0, 'message' => 'Invalid booking ID' ]); } $db = \Config\Database::connect(); $builder = $db->table('gss_plot_payments'); $where_booking = [ 'booking_id' => $booking_id, 'agreement_delete_status' => 'ACTIVE' ]; $update_status = [ 'agreement_delete_status' => 'INACTIVE' ]; $builder->where($where_booking)->update($update_status); if ($db->affectedRows() > 0) { return $this->response->setJSON([ 'result' => 1, 'message' => 'Deleted successfully' ]); } else { return $this->response->setJSON([ 'result' => 0, 'message' => 'No records updated' ]); } } public function delete_reg_id() { $id = $this->request->getPost('id'); if (!$id) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid ID']); } $db = \Config\Database::connect(); $builder = $db->table('gss_registration_amount_details'); $where = ['id' => $id, 'delete_status' => 'ACTIVE']; $update = ['delete_status' => 'INACTIVE']; $builder->where($where)->update($update); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No changes made']); } } //Payment details public function payment_details() { $admin_id = session()->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $uri=service('uri'); $booking_id = $uri->getSegment(2); $db = \Config\Database::connect(); // Agreement Payment Details $builder1 = $db->table('gss_plot_payments A'); $builder1->select('A.*, B.*, C.*, D.*, E.*, C.confirming_party1 as booking1_confirming_type, C.confirming_party2 as booking2_confirming_type, C.paytm_ref_no as paytm_num, C.upi_ref_no as upi_num, C.paytm_ref_no2 as paytm_num2, C.upi_ref_no2 as upi_num2'); $builder1->join('gss_bookings B', 'B.booking_id = A.booking_id'); $builder1->join('gss_booking_details C', 'C.detail_id = A.detail_id'); $builder1->join('gss_new_projects D', 'D.project_id = B.project_id'); $builder1->join('gss_plot_payment_types E', 'E.payment_id = A.payment_id'); $builder1->where([ 'A.delete_status' => 'ACTIVE', 'A.agreement_delete_status' => 'ACTIVE', 'B.delete_status' => 'ACTIVE', 'C.delete_status' => 'ACTIVE', 'D.delete_status' => 'ACTIVE', 'E.delete_status' => 'ACTIVE', 'A.booking_id' => $booking_id ]); $builder1->orderBy('A.payment_id', 'ASC'); $data['agreement_details'] = $builder1->get()->getRow(); // Installment Payment Details $builder2 = $db->table('gss_plot_payments A'); $builder2->select('A.*, B.*, C.*, D.*, E.*, C.paytm_ref_no as paytm_num, C.paytm_ref_no2 as paytm_num2, C.upi_ref_no as upi_num, C.upi_ref_no2 as upi_num2'); $builder2->join('gss_bookings B', 'B.booking_id = A.booking_id'); $builder2->join('gss_booking_details C', 'C.detail_id = A.detail_id'); $builder2->join('gss_new_projects D', 'D.project_id = B.project_id'); $builder2->join('gss_plot_payment_types E', 'E.payment_id = A.payment_id'); $builder2->where([ 'A.delete_status' => 'ACTIVE', 'A.install_delete_status' => 'ACTIVE', 'B.delete_status' => 'ACTIVE', 'C.delete_status' => 'ACTIVE', 'D.delete_status' => 'ACTIVE', 'E.delete_status' => 'ACTIVE', 'A.booking_id' => $booking_id ]); $builder2->orderBy('A.payment_id', 'ASC'); $data['installment_details'] = $builder2->get()->getResult(); // Registration Payment Details $builder3 = $db->table('gss_plot_payments A'); $builder3->select('A.*, B.*, C.*, D.*, E.*, C.paytm_ref_no as paytm_num, C.paytm_ref_no2 as paytm_num2, C.upi_ref_no as upi_num, C.upi_ref_no2 as upi_num2'); $builder3->join('gss_bookings B', 'B.booking_id = A.booking_id'); $builder3->join('gss_booking_details C', 'C.detail_id = A.detail_id'); $builder3->join('gss_new_projects D', 'D.project_id = B.project_id'); $builder3->join('gss_plot_payment_types E', 'E.payment_id = A.payment_id'); $builder3->where([ 'A.delete_status' => 'ACTIVE', 'A.registration_delete_status' => 'ACTIVE', 'B.delete_status' => 'ACTIVE', 'C.delete_status' => 'ACTIVE', 'D.delete_status' => 'ACTIVE', 'E.delete_status' => 'ACTIVE', 'A.booking_id' => $booking_id ]); $builder3->orderBy('A.payment_id', 'ASC'); $data['registration1_details'] = $builder3->get()->getRow(); // Payment Without Installment $builder4 = $db->table('gss_plot_payments A'); $builder4->select('A.*, B.*, C.*, D.*, E.*, C.confirming_party1 as booking1_confirming_type, C.confirming_party2 as booking2_confirming_type, C.paytm_ref_no as paytm_num, C.upi_ref_no as upi_num, C.paytm_ref_no2 as paytm_num2, C.upi_ref_no2 as upi_num2, C.upi_online_date2 as upi_date, C.paytm_online_date2 as paytm_date'); $builder4->join('gss_bookings B', 'B.booking_id = A.booking_id'); $builder4->join('gss_booking_details C', 'C.detail_id = A.detail_id'); $builder4->join('gss_new_projects D', 'D.project_id = B.project_id'); $builder4->join('gss_plot_payment_types E', 'E.payment_id = A.payment_id', 'left'); $builder4->where([ 'A.delete_status' => 'ACTIVE', 'B.delete_status' => 'ACTIVE', 'C.delete_status' => 'ACTIVE', 'D.delete_status' => 'ACTIVE', 'A.booking_id' => $booking_id ]); $builder4->orderBy('A.payment_id', 'DESC'); $data['others'] = $builder4->get()->getRow(); // Registration Amount Details $builder5 = $db->table('gss_registration_amount_details'); $builder5->where(['booking_id' => $booking_id, 'delete_status' => 'ACTIVE']); $regQuery = $builder5->get(); $data['more_registration_details'] = $regQuery->getResult() ?: ''; // Access Info $data['user_type_id'] = session()->get('user_type_id') ?? null; $data['access'] = []; // Fill this as needed return view('admin/payment_details', $data); } public function update_new_project() { helper(['form', 'url']); $db = \Config\Database::connect(); $builder = $db->table('gss_new_projects'); $project_id = $this->request->getPost('project_id'); $project_name = $this->request->getPost('project_name'); $project_type = $this->request->getPost('project_type'); $land_owner = $this->request->getPost('land_owner'); $marketing = $this->request->getPost('marketing'); $project_ownership = $this->request->getPost('project_ownership'); $confirming_party_name = $this->request->getPost('confirming_party_name'); $no_of_years = $this->request->getPost('no_of_years'); $per_sq_ft = $this->request->getPost('per_sq_ft'); $handled_by = $this->request->getPost('handled_by'); $nick_name = $this->request->getPost('nick_name'); $land_owner_address = $this->request->getPost('land_owner_address'); $p_name = ($marketing == 'Confirming Party') ? $confirming_party_name : $project_ownership; $updated_at = date('Y-m-d H:i:s'); // Fetch current row $file_data = $builder->where('project_id', $project_id)->get()->getRow(); $release_order_image = $file_data->release_image ?? ''; $conversion_order_image = $file_data->conversion_image ?? ''; $approved_plan_image = $file_data->approval_image ?? ''; $image = \Config\Services::image(); // Upload approved plan image if ($this->request->getFile('approved_plan_image')->isValid()) { $file = $this->request->getFile('approved_plan_image'); $newName = time() . $file->getName(); $file->move('project_uploads', $newName); $image->withFile('public/project_uploads/' . $newName)->resize(900, 900, true)->save('public/project_uploads/' . $newName); $approved_plan_image = preg_replace('/\s+/', '_', $newName); } // Upload release order image if ($this->request->getFile('release_order_image')->isValid()) { $file = $this->request->getFile('release_order_image'); $newName = time() . $file->getName(); $file->move('release_orders', $newName); $image->withFile('public/release_orders/' . $newName)->resize(900, 900, true)->save('public/release_orders/' . $newName); $release_order_image = preg_replace('/\s+/', '_', $newName); } // Upload conversion order images $url = []; $files = $this->request->getFiles()['conversion_order_image'] ?? []; if (!empty($files[0]) && $files[0]->isValid()) { foreach ($files as $file) { $timestamp = time() . rand(100, 999); $name = $timestamp . $file->getClientName(); $clean_name = preg_replace('/\s+/', '_', $name); $file->move('conversion_orders', $clean_name); $image->withFile('public/conversion_orders/' . $clean_name)->resize(900, 900, true)->save('public/conversion_orders/' . $clean_name); $url[] = $clean_name; } } // Check for duplicate project name $existing = $builder->where('project_name !=', $file_data->project_name) ->where('delete_status', 'ACTIVE') ->where('project_name', $project_name) ->get()->getResult(); if (count($existing) > 0) { echo json_encode(['result' => 2, 'message' => 'Project already exists']); return; } // Prepare update data $update_data = [ 'project_name' => $project_name, 'nick_name' => $nick_name, 'site_type' => $project_type, 'land_owner_id' => $land_owner, 'land_owner_address' => $land_owner_address, 'marketing' => $marketing, 'project_ownership' => $p_name, 'no_of_years' => $no_of_years, 'maintenance_per_sqft' => $per_sq_ft, 'project_status' => 'ONGOING', 'conversion_image' => implode(',', $url), 'release_image' => $release_order_image, 'approval_image' => $approved_plan_image, 'handled_by' => $handled_by, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ]; // Update main project table $builder->where('project_id', $project_id)->update($update_data); // Handle Excel import $excel = $this->request->getFile('excel_file'); if ($excel && $excel->isValid()) { $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($excel->getTempName()); $sheet = $spreadsheet->getActiveSheet(); $rows = $sheet->toArray(); $site_builder = $db->table('gss_new_sites'); $site_builder->where('project_id', $project_id)->delete(); for ($i = 1; $i < count($rows); $i++) { [$site_number, $north, $south, $east, $west, $sqmtrs, $sqft, $east_facing, $west_facing, $north_facing, $south_facing, $status] = $rows[$i]; $site_builder->insert([ 'project_id' => $project_id, 'site_number' => $site_number, 'north_in_mtrs' => number_format((float)$north, 2, '.', ''), 'south_in_mtrs' => number_format((float)$south, 2, '.', ''), 'east_in_mtrs' => number_format((float)$east, 2, '.', ''), 'west_in_mtrs' => number_format((float)$west, 2, '.', ''), 'total_in_sqmtrs' => number_format((float)$sqmtrs, 2, '.', ''), 'total_in_sqft' => number_format((float)$sqft, 2, '.', ''), 'east_facing' => $east_facing, 'west_facing' => $west_facing, 'north_facing' => $north_facing, 'south_facing' => $south_facing, 'status' => $status, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ]); } } // Insert multiple conversion order images if (!empty($url)) { $img_builder = $db->table('gss_project_conversion_orders'); $img_builder->where('project_id', $project_id)->delete(); foreach ($url as $img) { $img_builder->insert([ 'project_id' => $project_id, 'conversion_order' => $img, 'delete_status' => 'ACTIVE', 'created_at' => $updated_at ]); } } if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to update. Try again']); } } public function booked_site_details1() { $site_number = $this->request->getPost('site_number'); $project_id = $this->request->getPost('project_id'); $model = new \App\Models\GssModel(); $get_ids = $model->test_details($project_id, $site_number); $booking_id = 0; $detail_id = 0; if (!empty($get_ids)) { $booking_id = $get_ids['booking_id']; $detail_id = $get_ids['detail_id']; $check_ids = $model->get_payments_types_result($booking_id, $detail_id); $check_ids_rows = $model->get_payments_types($booking_id, $detail_id); if (!empty($check_ids_rows)) { $check_ids_row = $check_ids_rows; } else { $check_ids_row = $model->get_registration_amount($booking_id); } $get_reg_amt = $model->registration_details_get($booking_id, $detail_id); $get_reg_amt = !empty($get_reg_amt) ? $get_reg_amt : ''; } $check_site = $model->project_details($site_number, $project_id); if (!empty($check_site)) { $site_result = $model->payment_booking_details($site_number, $project_id, $booking_id); $due_amounts = $model->due_amounts($site_number, $project_id); if (!empty($site_result)) { $agreement_details = $model->get_agreement_amount_details($booking_id, $detail_id); $initial_reg_details = $model->registration_payment_details($booking_id); $installment_details = $model->get_installment_amount_details($booking_id, $detail_id); if ($site_result['booking_status'] == 'CANCELLED') { return $this->response->setJSON([ 'result' => 3, 'message' => 'Site number ' . $site_number . ' has been cancelled' ]); } else { return $this->response->setJSON([ 'result' => 1, 'booking_details' => $site_result, 'due_amounts' => $due_amounts, 'row_amounts' => $check_ids, 'amounts' => $check_ids_row, 'registration_amt' => $get_reg_amt, 'agreement_details' => $agreement_details, 'registration_details'=> $initial_reg_details, 'installment_details' => $installment_details ]); } } else { return $this->response->setJSON([ 'result' => 0, 'message' => 'Site number ' . $site_number . ' not booked' ]); } } else { return $this->response->setJSON([ 'result' => 2, 'message' => 'Site number ' . $site_number . ' not found' ]); } } public function installment_receipt_details() { $uri = service('uri'); $booking_id = $uri->getSegment(2); $payment_id = $uri->getSegment(3); $ack_no = $uri->getSegment(4); $table = 'gss_bookings'; $broker_table = 'gss_brokers'; $instal_table = 'gss_booking_installments'; $project_table = 'gss_new_projects'; $land_owner_table = 'gss_land_owners'; $model = new \App\Models\GssModel(); $site_result = $model->user_site_booking_details1($booking_id); $data['site_result'] = $site_result; $where_instal = ['booking_id' => $booking_id, 'delete_status' => 'ACTIVE']; $instal_result = $model->get_where_row($instal_table, $where_instal); $data['instal_result'] = $instal_result; $detail_id = $instal_result->booking_detal_id ?? null; $where_project = ['booking_id' => $booking_id]; $get_project = $model->get_where_row($table, $where_project); $project_id = $get_project->project_id ?? null; $where_proj = ['project_id' => $project_id]; $get_project_details = $model->get_where_row($project_table, $where_proj); $data['project'] = $get_project_details; $land_owner = $get_project_details->land_owner_id ?? null; $where_land_owner = ['owner_id' => $land_owner]; $get_land_owner = $model->get_where_row($land_owner_table, $where_land_owner); $data['land_owner'] = $get_land_owner; $data['ack_no'] = $ack_no; $data['res'] = $model->get_where_installments($payment_id); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); if ($get_land_owner && $get_land_owner->name == 'GSS Project Consultants') { return view('admin/gss_installment_receipt', $data); } else { return view('admin/gss_installment_ack', $data); } } //Payments list public function payments_list() { $session = session(); if ($session->has('admin_id')) { $GssNewProjectsModel= new GssNewProjectsModel(); $projectTable = 'gss_new_projects'; $whereProject = ['delete_status' => 'ACTIVE', 'project_status' => 'ONGOING']; $data['projects'] = $GssNewProjectsModel->get_where_result($projectTable, $whereProject); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/individual_payment_details', $data); } else { return redirect()->to('/'); } } public function remove_payment_details() { $admin_id = session()->get('admin_id'); if (!$admin_id) { return redirect()->to('/'); } $uri=service('uri'); $booking_id = $uri->getSegment(2); $db = \Config\Database::connect(); $builder = $db->table('gss_new_projects'); $where_project = [ 'delete_status' => 'ACTIVE', 'project_status' => 'ONGOING' ]; $projects = $builder->where($where_project)->get()->getResult(); // Inline access logic $user_type_id = session()->get('user_type_id') ?? null; $access = session()->get('access') ?? []; $data = [ 'booking_id' => $booking_id, 'projects' => $projects, 'user_type_id' => $user_type_id, 'access' => $access ]; return view('admin/remove_individual_payments', $data); } public function delete_agreement_amount() { $table = 'gss_plot_payments'; $payment_id = $this->request->getPost('payment_id'); $where = array('payment_id'=>$payment_id); $data = array('agreement_amount'=>'','agreement_date'=>'','agreement_payment_mode'=>''); $result = $this->gss_model->update($where,$table,$data); $table = 'gss_plot_payment_types'; $data = array('agreement_cheque_no'=>'0','agreement_cheque_date'=>'','agreement_bank'=>'0','agreement_vtr_no'=>'','agreement_online_date'=>'','agreement_dd_no'=>'0','agreement_dd_date'=>'','agreement_dd_bank'=>'0'); $result = $this->gss_model->update($where,$table,$data); if($this->db->affected_rows() > 0) { echo json_encode(array('result'=>1,'message'=>'Deleted successfully')); } else { echo json_encode(array('result'=>0)); } } //Delete payment public function delete_individual_payment() { $booking_id = $this->request->getPost('booking_id'); $db = \Config\Database::connect(); // Get the row from gss_plot_payments $paymentBuilder = $db->table('gss_plot_payments'); $type_result = $paymentBuilder ->where(['booking_id' => $booking_id, 'delete_status' => 'ACTIVE']) ->get() ->getRow(); if ($type_result && isset($type_result->payment_id)) { $payment_id = $type_result->payment_id; // Set deletion status $delete_status = ['delete_status' => 'INACTIVE']; // Update gss_plot_payment_types $typeBuilder = $db->table('gss_plot_payment_types'); $typeBuilder->where(['payment_id' => $payment_id])->update($delete_status); // Update gss_plot_payments $paymentBuilder->where(['booking_id' => $booking_id])->update($delete_status); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } } return $this->response->setJSON(['result' => 0]); } //Dues list // public function get_dues_list() // { // $project = $this->request->getGet('project'); // Get parameter from URL // $builder = $this->db->table('gss_plot_payments A') // ->select('A.*, B.*, C.*, D.*') // ->join('gss_bookings B', 'B.booking_id = A.booking_id') // ->join('gss_booking_details C', 'C.detail_id = A.detail_id') // ->join('gss_new_projects D', 'D.project_id = B.project_id') // ->where('A.dues_option', 'dues') // ->where('A.delete_status', 'ACTIVE') // ->where('B.delete_status', 'ACTIVE') // ->where('C.delete_status', 'ACTIVE') // ->where('D.delete_status', 'ACTIVE'); // if (!empty($project)) { // $builder->where('B.project_id', $project); // } // $builder->orderBy('A.payment_id', 'DESC') // ->groupBy('A.booking_id'); // $result = $builder->get()->getResult(); // $array = []; // foreach ($result as $ress) { // $data = [ // 'booking_id' => $ress->booking_id, // 'project_name' => $ress->project_name, // 'site_number' => $ress->site_number, // 'customer_name' => $ress->customer_name, // 'dimension' => $ress->dimension, // 'dues_option' => $ress->dues_option, // 'remarks' => $ress->remarks, // 'registration_status' => $ress->registration_status, // 'registration_date' => ($ress->registration_status == "Pending") ? "" : $ress->registration_date // ]; // array_push($array, $data); // } // if ($array) { // return $this->response->setJSON($array); // } else { // return $this->response->setJSON(['result' => 0]); // } // } //Dues list public function get_dues_all_list() { $builder = $this->db->table('gss_plot_payments A') ->select('A.*, B.*, C.*, D.*') ->join('gss_bookings B', 'B.booking_id = A.booking_id') ->join('gss_booking_details C', 'C.detail_id = A.detail_id') ->join('gss_new_projects D', 'D.project_id = B.project_id') ->where('A.dues_option', 'dues') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('C.delete_status', 'ACTIVE') ->where('D.delete_status', 'ACTIVE') ->orderBy('A.payment_id', 'DESC') ->groupBy('A.booking_id'); $result = $builder->get()->getResult(); $array = []; foreach ($result as $ress) { $data = [ 'booking_id' => $ress->booking_id, 'project_name' => $ress->project_name, 'site_number' => $ress->site_number, 'customer_name' => $ress->customer_name, 'dimension' => $ress->dimension, 'dues_option' => $ress->dues_option, 'remarks' => $ress->remarks, 'registration_status' => $ress->registration_status, 'registration_date' => ($ress->registration_status == "Pending") ? "" : $ress->registration_date ]; array_push($array, $data); } if ($array) { return $this->response->setJSON($array); } else { return $this->response->setJSON(['result' => 0]); } } //Dues list public function get_dues_list() { $project = $this->request->getGet('project'); // Get parameter from URL $builder = $this->db->table('gss_plot_payments A') ->select('A.*, B.*, C.*, D.*') ->join('gss_bookings B', 'B.booking_id = A.booking_id') ->join('gss_booking_details C', 'C.detail_id = A.detail_id') ->join('gss_new_projects D', 'D.project_id = B.project_id') ->where('A.dues_option', 'dues') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('C.delete_status', 'ACTIVE') ->where('D.delete_status', 'ACTIVE'); if (!empty($project)) { $builder->where('B.project_id', $project); } $builder->orderBy('A.payment_id', 'DESC') ->groupBy('A.booking_id'); $result = $builder->get()->getResult(); $array = []; foreach ($result as $ress) { $data = [ 'booking_id' => $ress->booking_id, 'project_name' => $ress->project_name, 'site_number' => $ress->site_number, 'customer_name' => $ress->customer_name, 'dimension' => $ress->dimension, 'dues_option' => $ress->dues_option, 'remarks' => $ress->remarks, 'registration_status' => $ress->registration_status, 'registration_date' => ($ress->registration_status == "Pending") ? "" : $ress->registration_date ]; array_push($array, $data); } if ($array) { return $this->response->setJSON($array); } else { return $this->response->setJSON(['result' => 0]); } } public function booking_list() { $gss_model=new Gss_model(); $table = 'gss_bookings'; $where = array('delete_status'=>'ACTIVE'); $order_by = "booking_id"; $result = $gss_model->get_all_bookings(); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function get_table_details() { $type = $this->request->getGet('type'); $model=new Gss_model(); $result = $model->assoc_reports($type); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON([ 'result' => 0, 'message' => 'No Details found' ]); } } //Payment list public function payment_list() { $db = \Config\Database::connect(); $builder = $this->db->table('gss_plot_payments A') ->select('A.*, B.*, C.*, D.*, B.booking_status as b_booking_status') ->join('gss_bookings B', 'B.booking_id = A.booking_id') ->join('gss_booking_details C', 'C.detail_id = A.detail_id') ->join('gss_new_projects D', 'D.project_id = B.project_id') ->where('A.delete_status', 'ACTIVE') ->where('B.delete_status', 'ACTIVE') ->where('C.delete_status', 'ACTIVE') ->where('D.delete_status', 'ACTIVE') ->orderBy('A.payment_id', 'DESC') ->groupBy('A.booking_id'); $result = $builder->get()->getResult(); if ($result) { return $this->response->setJSON($result); } else { return $this->response->setJSON(['result' => 0]); } } //Payments list public function dues_list() { $admin_id = session()->get('admin_id'); if($admin_id) { $GssNewProjectsModel = new GssNewProjectsModel(); $project_table = 'gss_new_projects'; $where_project = array('delete_status'=>'ACTIVE','project_status'=>'ONGOING'); $order_by = 'project_name'; $data['projects'] = $GssNewProjectsModel->get_where_result_alphabetical($project_table,$where_project,$order_by); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/dues_list',$data); } else { redirect('/'); } } //new public function land_developers() { $admin_id = session()->get('admin_id'); if($admin_id) { $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/land_developer_form',$data); } else { redirect('/'); } } public function add_land_developers() { $db = \Config\Database::connect(); $name = $this->request->getPost('name'); $email = $this->request->getPost('email'); $mobile = $this->request->getPost('mobile'); $address = $this->request->getPost('address'); $pan_or_adhar = $this->request->getPost('pan_or_adhar'); $file_name = ""; if ($this->request->getFile('id_proof_image')->isValid()) { $file = $this->request->getFile('id_proof_image'); if (!$file->hasMoved()) { $newName = time() . $file->getClientName(); $file_name = $newName; $file->move('public/land_developers_images', $newName); } } $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $data = [ 'name' => $name, 'email' => $email, 'mobile' => $mobile, 'address' => $address, 'pan_or_adhar_number' => $pan_or_adhar, 'id_proof_image' => $file_name, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $builder = $db->table('gss_land_developers'); $query = $builder->select('mobile')->where('delete_status', 'ACTIVE')->get(); $array = []; foreach ($query->getResult() as $value) { $array[] = $value->mobile; } if (in_array($mobile, $array)) { return $this->response->setJSON(['result' => 2, 'message' => "Contact number already exists"]); } else { $insert = $builder->insert($data); if ($insert) { return $this->response->setJSON(['result' => 1, 'message' => "Land developer details added successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong.. try again"]); } } } public function land_developers_list() { $gss_model = new Gss_model(); $table = 'gss_land_developers'; $where = ['delete_status'=>'ACTIVE']; $order_by = "developer_id"; $result = $gss_model->get_where_result_orderby($table,$where,$order_by); if($result) { return $this->response->setJSON(['result'=>1,'land_developers_list'=>$result]); } else { return $this->response->setJSON(['result'=>0]); } } public function edit_land_developer() { $gss_model = new Gss_model(); $table = 'gss_land_developers'; $developer_id = $this->request->getPost('developer_id'); $where = array('developer_id'=>$developer_id,'delete_status'=>'ACTIVE'); $result = $gss_model->get_where_row($table,$where); if($result) { return $this->response->setJSON(['land_developer_details'=>$result,'result'=>1]); } else { return $this->response->setJSON(['result'=>0]); } } public function update_land_developer() { $table = 'gss_land_developers'; $developer_id = $this->request->getPost('developer_id'); $name = $this->request->getPost('name'); $email = $this->request->getPost('email'); $mobile = $this->request->getPost('mobile'); $address = $this->request->getPost('address'); $pan_or_adhar = $this->request->getPost('pan_or_adhar'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); $db = \Config\Database::connect(); $builder = $db->table($table); // Fetch existing record $file_data = $builder->where('developer_id', $developer_id)->get()->getRow(); if (!$file_data) { return $this->response->setJSON(['result' => 0, 'message' => 'Developer not found']); } $id_proof = $file_data->id_proof_image; $file = $this->request->getFile('id_proof_image'); if (!$file || !$file->isValid()) { $id_proof_final = $id_proof; } else { $newName = time() . '_' . $file->getClientName(); $file->move('public/land_developers_images', $newName); $id_proof_final = $newName; } $data = [ 'name' => $name, 'email' => $email, 'mobile' => $mobile, 'address' => $address, 'pan_or_adhar_number' => $pan_or_adhar, 'id_proof_image' => $id_proof_final, 'delete_status' => 'ACTIVE', 'updated_at' => $updated_at ]; // Check for duplicate mobile numbers (except the current one) $all_active = $builder->where('delete_status', 'ACTIVE')->get()->getResult(); $mobiles = []; foreach ($all_active as $dev) { if ($dev->mobile != $file_data->mobile) { $mobiles[] = $dev->mobile; } } if (in_array($mobile, $mobiles)) { return $this->response->setJSON(['result' => 2, 'message' => 'Contact number already exists']); } else { $result = $builder->where('developer_id', $developer_id)->update($data); if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to update. Try again']); } } } public function site_map_form() { $admin_id =session()->get('admin_id'); $gss_model = new Gss_model(); if($admin_id) { $table='gss_new_projects'; $condition=['delete_status'=>'ACTIVE']; $data['project'] = $gss_model->get_where_result($table,$condition); $data['mappings'] = $gss_model->get_where_result_mapping_sketch(); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/mapping_form',$data); } else { redirect('/'); } } public function add_mapping_sketch() { helper(['form', 'url']); $db = \Config\Database::connect(); $request = service('request'); $imageLib = \Config\Services::image(); $id = $request->getPost('id'); $createdAt = date('Y-m-d H:i:s', strtotime('now')); $fileName = ""; if ($this->request->getFile('hobli_sketch')->isValid()) { $file = $this->request->getFile('hobli_sketch'); if (!$file->hasMoved()) { $newName = time() . $file->getClientName(); $targetPath = ROOTPATH . 'public/mapping_image/' . $newName; $file->move(ROOTPATH . 'public/mapping_image', $newName); // Resize image $imageLib->withFile($targetPath) ->resize(900, 900, true) ->save($targetPath); $fileName = $newName; } } $builder = $db->table('gss_mapping_sketch'); // Check if sketch exists for this project $existingSketch = $builder->where(['project_id' => $id, 'delete_status' => 'ACTIVE'])->get()->getResult(); if (count($existingSketch) > 0) { return $this->response->setJSON(['result' => 2, 'message' => 'Sketch already exists for this project']); } $data = [ 'project_id' => $id, 'image' => $fileName, 'delete_status' => 'ACTIVE', 'created_at' => $createdAt, 'modified_at' => $createdAt ]; $insert = $builder->insert($data); if ($insert) { return $this->response->setJSON(['result' => 1, 'message' => 'Sketch added successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Something went wrong.. try again']); } } public function get_project_sketches() { $gss_model = new Gss_model(); $result = $gss_model->get_where_result_mapping_sketch(); if($result) { return $this->response->setJSON(['result'=>1,'sketch_list'=>$result]); } else { return $this->response->setJSON(['result'=>0]); } } public function mapping_sketch() { $session = session(); $admin_id = $session->get('admin_id'); if ($admin_id) { $sketch_id = $this->request->getUri()->getSegment(2); $table = 'gss_mapping_sketch'; $where = ['sketch_id' => $sketch_id, 'delete_status' => 'ACTIVE']; $this->gss_model = new \App\Models\Gss_model(); // Use same model name as CI3 $data['sketch'] = $this->gss_model->get_where_row($table, $where); $data['project_id'] = $data['sketch']->project_id; $where_data = ['project_id' => $data['project_id'], 'delete_status' => 'ACTIVE']; $table_site = 'gss_new_sites'; $data['site'] = $this->gss_model->get_where_result($table_site, $where_data); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/sketch_mapping', $data); } else { return redirect()->to('/'); } } public function add_mapping_tags() { $project_id = $this->request->getPost('project_id'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $area_tag = $this->request->getPost('area_tag'); $site_ids = $this->request->getPost('site_ids'); $project_status = $this->request->getPost('project_status'); $db = \Config\Database::connect(); $builder = $db->table('gss_mapping'); $success = false; foreach ($area_tag as $index => $val) { $data = [ 'project_id' => $project_id, 'area_tag' => $val, 'site_id' => $site_ids[$index], 'project_status' => $project_status[$index], 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $success = $builder->insert($data); } if ($success) { return $this->response->setJSON(['result' => 1, 'message' => "Data added successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong.. try again"]); } } public function get_map_sketch_data() { $gss_model = new \App\Models\Gss_model(); $table = 'gss_mapping_sketch'; $sketch_id = $this->request->getPost('sketch_id'); $where = ['sketch_id'=>$sketch_id,'delete_status'=>'ACTIVE']; $result = $gss_model->get_where_row($table,$where); if($result) { return $this->response->setJSON(['sketch_data'=>$result,'result'=>1]); } else { return $this->response->setJSON(['result'=>0]); } } public function update_map_sketch() { $sketch_id = $this->request->getPost('hobli_sketch_id'); $project_id = $this->request->getPost('id'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); $db = \Config\Database::connect(); $builder = $db->table('gss_mapping_sketch'); // Get existing file data $file_data = $builder->where('sketch_id', $sketch_id)->get()->getRow(); $hobli_sketch = $file_data ? $file_data->image : ''; helper(['form', 'filesystem']); // Load helper for file functions // Handle file upload $file = $this->request->getFile('hobli_sketch'); if ($file && $file->isValid() && !$file->hasMoved()) { $newName = time() . $file->getClientName(); $target = ROOTPATH . 'public/mapping_image/' . $newName; $file->move(ROOTPATH . 'public/mapping_image', $newName); $file_name = $newName; // Resize using Image service $image = \Config\Services::image() ->withFile($target) ->resize(900, 900, true, 'height') ->save($target); } else { $file_name = $hobli_sketch; } // Prepare update data $data = [ 'image' => $file_name, 'modified_at' => $updated_at ]; $builder->where('sketch_id', $sketch_id)->update($data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => "Updated successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Failed to update. Try again"]); } } public function update_area_coordinate_mapping() { $session = session(); $admin_id = $session->get('admin_id'); if ($admin_id) { $sketch_id = $this->request->getUri()->getSegment(2); $table_sketch = 'gss_mapping'; $where = ['mapping_id' => $sketch_id]; $gss_new_projects_table = 'gss_new_projects'; $data['sketch_id'] = $sketch_id; // Load model $this->gss_model = new \App\Models\Gss_model(); $details = $this->gss_model->get_where_row($table_sketch, $where); $where_new_projects = ['project_id' => $details->project_id]; $data['coordinates'] = $this->gss_model->get_where_result($table_sketch, $where_new_projects); $data['project'] = $this->gss_model->get_where_row($gss_new_projects_table, $where_new_projects); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/update_area_coordinate_mapping', $data); } else { return redirect()->to('/'); } } public function get_mapping_tags() { $project_id = $this->request->getPost('project_id'); $table = 'gss_mapping'; $where = ['project_id' => $project_id, 'delete_status' => 'ACTIVE']; $this->gss_model = new \App\Models\Gss_model(); $result = $this->gss_model->get_where_result($table, $where); if ($result) { return $this->response->setJSON(['result' => 1, 'mapping_tags' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function delete_mapping_code() { $mapping_id = $this->request->getPost('mapping_id'); $table = 'gss_mapping'; $this->gss_model = new \App\Models\Gss_model(); // Using query builder to update the record $builder = $this->db->table($table); $result = $builder->set('delete_status', 'INACTIVE') ->where('mapping_id', $mapping_id) ->update(); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0]); } } public function update_mapping_code() { $mapping_id = $this->request->getPost('mapping_id'); $area_tag = $this->request->getPost('area_tag'); $site_id = $this->request->getPost('site_id'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $updated_at = $date->format('Y-m-d H:i:s'); $table = 'gss_mapping'; // Load the model $this->gss_model = new \App\Models\Gss_model(); $builder = $this->db->table($table); $result = false; foreach ($mapping_id as $index => $val) { $data = [ 'area_tag' => $area_tag[$index], 'site_id' => $site_id[$index], 'modified_at' => $updated_at ]; // Update the mapping record $builder->set($data) ->where('mapping_id', $val) ->update(); if ($this->db->affectedRows() > 0) { $result = true; } } if ($result) { return $this->response->setJSON(['result' => 1, 'message' => 'Updated successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'Failed to update. Try again']); } } public function delete_site_sketch() { $sketch_id = $this->request->getPost('sketch_id'); $table = 'gss_mapping_sketch'; $data = ['delete_status' => 'INACTIVE']; $builder = $this->db->table($table); $builder->where('sketch_id', $sketch_id) ->update($data); if ($this->db->affectedRows() > 0) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted successfully']); } else { return $this->response->setJSON(['result' => 0]); } } public function edit_booking_details() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $web_table = 'gss_webportals'; $broker_table = 'gss_brokers'; $project_table = 'gss_new_projects'; $where_portal = array('delete_status'=>'ACTIVE'); $where_reference = array('delete_status'=>'ACTIVE','type'=>'Executives'); $where_logistics = array('delete_status'=>'ACTIVE','type'=>'Logistic'); $where_associate = array('delete_status'=>'ACTIVE','type'=>'Associate'); $where_subassociate = array('delete_status'=>'ACTIVE','type'=>'Sub Associate'); $where_project = array('delete_status'=>'ACTIVE'); $order_by_portal = 'webportal'; $order_by = 'associate_name'; $order_by_project = 'project_name'; $data['webportals'] = $gss_model->get_where_result_alphabetical($web_table,$where_portal,$order_by_portal); $data['reference'] = $gss_model->get_where_result_orderby_asc($broker_table,$where_reference,$order_by); $data['logistics'] = $gss_model->get_where_result_orderby_asc($broker_table,$where_logistics,$order_by); $data['associates'] = $gss_model->get_where_result_orderby_asc($broker_table,$where_associate,$order_by); $data['subassociates'] = $gss_model->get_where_result_orderby_asc($broker_table,$where_subassociate,$order_by); $data['projects'] = $gss_model->get_where_result_orderby_asc($project_table,$where_project,$order_by_project); $booking_id = service('uri')->getSegment(2); $data['booking'] = $gss_model->single_booking_details($booking_id); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/edit_booking_form',$data); } else { redirect('/'); } } public function update_booking() { $db = \Config\Database::connect(); $gss_model=new Gss_model(); $booking_table = 'gss_bookings'; $detail_table = 'gss_booking_details'; $instal_table = 'gss_booking_installments'; $booking_id = $this->request->getpost('booking_id'); $detail_id = $this->request->getpost('detail_id'); $installment_id = $this->request->getpost('installment_id'); $customer_name = $this->request->getpost('customer_name'); $relation = $this->request->getpost('relation'); $fa_hu_name = $this->request->getpost('fa_hu_name'); $email = $this->request->getpost('email'); $alternative_email = $this->request->getpost('alternative_email'); $mobile1 = $this->request->getpost('mobile1'); $mobile2 = $this->request->getpost('mobile2'); $office_no = $this->request->getpost('office_no'); $bday = $this->request->getpost('bday'); if($bday !="") { $bday = !empty($bday) ? (new \DateTime($bday))->format('Y-m-d') : null; } $doa = $this->request->getpost('doa'); if($doa !="") { $doa = !empty($doa) ? (new \DateTime($doa))->format('Y-m-d') : null; } $address = $this->request->getpost('address'); $id_name = $this->request->getpost('id_name'); $id_no = $this->request->getpost('id_no'); $nominee = $this->request->getpost('nominee'); $nominee_con_no = $this->request->getpost('nominee_con_no'); $reference = $this->request->getpost('reference'); $web_portal = $this->request->getpost('web_portal'); $logistics = $this->request->getpost('logistics'); $associate = $this->request->getpost('associate'); $subassociate = $this->request->getpost('subassociate'); $source_type = $this->request->getpost('source_type'); $source_bank_name = $this->request->getpost('source_bank_name'); $project_id = $this->request->getpost('project_id'); $site_number = $this->request->getpost('site_number'); $site_dimension = $this->request->getpost('site_dimension'); $booking_date1 = $this->request->getpost('booking_date1'); $reference_two = $this->request->getpost('reference_two'); $logistics_two = $this->request->getpost('logistics_two'); if($booking_date1 != "") { $booking_date1 = !empty($booking_date1) ? (new \DateTime($booking_date1))->format('Y-m-d') : null; } $booking_amount_1 = $this->request->getpost('booking_amount1'); $booking_amount1 = str_replace(',', '', $booking_amount_1); $booking_date2 = $this->request->getpost('booking_date2'); if($booking_date2 != "") { $booking_date2 = !empty($booking_date2) ? (new \DateTime($booking_date2))->format('Y-m-d') : null; } $booking_amount_2 = $this->request->getpost('booking_amount2'); $booking_amount2 = str_replace(',', '', $booking_amount_2); $instal_due_date = $this->request->getpost('instal_due_date'); if($instal_due_date != "") { $instal_due_date = !empty($instal_due_date) ? (new \DateTime($instal_due_date))->format('Y-m-d') : null; } $instal_due_amounts = $this->request->getpost('instal_due_amount'); $instal_due_amount = str_replace(',', '', $instal_due_amounts); $reg_due_date = $this->request->getpost('reg_due_date'); if($reg_due_date != "") { $reg_due_date = !empty($reg_due_date) ? (new \DateTime($reg_due_date))->format('Y-m-d') : null; } $reg_due_amounts = $this->request->getpost('reg_due_amount'); $reg_due_amount = str_replace(',', '', $reg_due_amounts); $sale_agree_date = $this->request->getpost('sale_agree_date'); if($sale_agree_date != "") { $sale_agree_date = !empty($sale_agree_date) ? (new \DateTime($sale_agree_date))->format('Y-m-d') : null; } $sale_agree_amounts = $this->request->getpost('sale_agree_amount'); $sale_agree_amount = str_replace(',', '', $sale_agree_amounts); $tsvs = $this->request->getpost('tsv'); $tsv = str_replace(',', '', $tsvs); $per_sqft = $this->request->getpost('per_sqft'); $land_owner_rate = $this->request->getpost('land_owner_rate'); $land_owner_amounts = $this->request->getpost('land_owner_amount'); $land_owner_amount = str_replace(',', '', $land_owner_amounts); $gss_rate = $this->request->getpost('gss_rate'); $gss_amounts = $this->request->getpost('gss_amount'); $gss_amount = str_replace(',', '', $gss_amounts); $reg_date_type = $this->request->getpost('reg_date_type'); $confirming_party1 =$this->request->getpost('owners_type1'); $confirming_party2 =$this->request->getpost('owners_type2'); $payment_type = $this->request->getpost('payment_type'); $check_no = ''; $check_date = ''; $bank_name = ''; $vtr_no = ''; $online_date = ''; $dd_no = ''; $dd_date = ''; $dd_bank = ''; $ref_no =''; $paytm_date =''; $upi_ref_no =''; $upi_date =''; if($payment_type == 'Cheque') { $check_no = $this->request->getpost('check_no'); $check_date = $this->request->getpost('check_date'); if($check_date != "") { $check_date = !empty($check_date) ? (new \DateTime($check_date))->format('Y-m-d') : null; } $bank_name = $this->request->getpost('bank_name'); } else if($payment_type == 'Online Payment') { $vtr_no = $this->request->getpost('vtr_no'); $online_date = $this->request->getpost('online_date'); if($online_date != "") { $online_date = !empty($online_date) ? (new \DateTime($online_date))->format('Y-m-d') : null; } } else if($payment_type == 'DD') { $dd_no = $this->request->getpost('dd_no'); $dd_date = $this->request->getpost('dd_date'); if($dd_date != "") { $dd_date = !empty($dd_date) ? (new \DateTime($dd_date))->format('Y-m-d') : null; } $dd_bank = $this->request->getpost('dd_bank'); } else if($payment_type == 'Paytm Payment') { $ref_no = $this->request->getpost('ref_no'); $paytm_date = $this->request->getpost('paytm_date'); if($paytm_date != "") { $paytm_date = !empty($paytm_date) ? (new \DateTime($paytm_date))->format('Y-m-d') : null; } } else if($payment_type == 'UPI Payment') { $upi_ref_no = $this->request->getpost('upi_ref_no'); $upi_date = $this->request->getpost('upi_date'); if($upi_date != "") { $upi_date = !empty($upi_date) ? (new \DateTime($upi_date))->format('Y-m-d') : null; } } //-----------------------------------------------------------// $payment_type2 = $this->request->getpost('payment_type2'); $check_no2 = ''; $check_date2 = ''; $bank_name2 = ''; $vtr_no2 = ''; $online_date2 = ''; $dd_no2 = ''; $dd_date2 = ''; $dd_bank2 = ''; $ref_no1 =''; $paytm_date1 =''; $upi_ref_no1 =''; $upi_date1 =''; if($payment_type2 == 'Cheque') { $check_no2 = $this->request->getpost('check_no2'); $check_date2 = $this->request->getpost('check_date2'); if($check_date2 != "") { $check_date2 = !empty($check_date2) ? (new \DateTime($check_date2))->format('Y-m-d') : null; } $bank_name2 = $this->request->getpost('bank_name2'); } else if($payment_type2 == 'Online Payment') { $vtr_no2 = $this->request->getpost('vtr_no2'); $online_date2 = $this->request->getpost('online_date2'); if($online_date2 != "") { $online_date2 = !empty($online_date2) ? (new \DateTime($online_date2))->format('Y-m-d') : null; } } else if($payment_type2 == 'DD') { $dd_no2 = $this->request->getpost('dd_no2'); $dd_date2 = $this->request->getpost('dd_date2'); if($dd_date2 != "") { $dd_date2 = !empty($dd_date2) ? (new \DateTime($dd_date2))->format('Y-m-d') : null; } $dd_bank2 = $this->request->getpost('dd_bank2'); } else if($payment_type2 == 'Paytm Payment') { $ref_no1 = $this->request->getpost('ref_no1'); $paytm_date1 = $this->request->getpost('paytm_date1'); if($paytm_date1 != "") { $paytm_date1 = !empty($paytm_date1) ? (new \DateTime($paytm_date1))->format('Y-m-d') : null; } } else if($payment_type2 == 'UPI Payment') { $upi_ref_no1 = $this->request->getpost('upi_ref_no1'); $upi_date1 = $this->request->getpost('upi_date1'); if($upi_date1 != "") { $upi_date1 = !empty($upi_date1) ? (new \DateTime($upi_date1))->format('Y-m-d') : null; } } //---------------------------------------------------------// $mobile = json_encode(array($mobile1, $mobile2)); $load = $image = \Config\Services::image(); $id_scan = ""; $application_scan = ""; $where_booking = array('booking_id'=>$booking_id,'delete_status'=>'ACTIVE'); if($_FILES) { if(empty($_FILES['id_scan']['name'])) { $id_result = $gss_model->get_where_row($booking_table,$where_booking); $id_scan = $id_result->idproof_image; } else { $target='public/booking_uploads/'; $target.=time().$_FILES['id_scan']['name']; $id_scan=time().$_FILES['id_scan']['name']; $image=$target; move_uploaded_file($_FILES['id_scan']['tmp_name'],$target); $config['source_image']=$target; $config['maintain_ratio']=TRUE; $image = \Config\Services::image(); $image->withFile($target) ->resize(200, 150, true) // Resize the image while maintaining the aspect ratio ->save($target); } if(empty($_FILES['application_scan']['name'])) { $appln_result = $gss_model->get_where_row($detail_table,$where_booking); $application_scan = $appln_result->application_scan; } else { $target='public/booking_uploads/'; $target.=time().$_FILES['application_scan']['name']; $application_scan=time().$_FILES['application_scan']['name']; $image=$target; move_uploaded_file($_FILES['application_scan']['tmp_name'],$target); $config['source_image']=$target; $config['maintain_ratio']=TRUE; $image = \Config\Services::image(); $image->withFile($target) ->resize(200, 150, true) // Resize the image while maintaining the aspect ratio ->save($target); } } $khata_status = $this->request->getpost('khata_status'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $booking_data = array( 'project_id' => $project_id, 'customer_name' => $customer_name, 'relation' => $relation, 'father_or_husband' => $fa_hu_name, 'email' => $email, 'alternative_email' => $alternative_email, 'mobile1' => $mobile1, 'mobile2' => $mobile2, 'dob' => $bday, 'doa' => $doa, 'address' => $address, 'nominee_name' => $nominee, 'nominee_contact' => $nominee_con_no, 'office_number' => $office_no, 'idproof_name' => $id_name, 'idproof_number' => $id_no, 'idproof_image' => $id_scan, 'webportal' => $web_portal, 'logistics' => $logistics, 'reference' => $reference, 'associate' => $associate, 'subassociate' => $subassociate, 'reference_two' => $reference_two, 'logistics_two' => $logistics_two, 'source_type' => $source_type, 'source_bank_name' => $source_bank_name, 'khata_status' => $khata_status, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ); $detail_data = array( 'booking_id' => $booking_id, 'project_id' => $project_id, 'booking_date1' => $booking_date1, 'booking_amount1' => $booking_amount1, 'booking_date2' => $booking_date2, 'booking_amount2' => $booking_amount2, 'booking_payment_type' => $payment_type, 'confirming_party1' =>$confirming_party1, 'confirming_party2' =>$confirming_party2, 'check_no' => $check_no, 'check_date' => $check_date, 'bank_name' => $bank_name, 'vtr_no' => $vtr_no, 'online_date' => $online_date, 'dd_no' => $dd_no, 'dd_date' => $dd_date, 'dd_bank' => $dd_bank, 'paytm_ref_no' => $ref_no, 'paytm_online_date' => $paytm_date, 'upi_ref_no' =>$upi_ref_no, 'upi_online_date' =>$upi_date, 'booking_payment_type2' => $payment_type2, 'check_no2' => $check_no2, 'check_date2' => $check_date2, 'bank_name2' => $bank_name2, 'vtr_no2' => $vtr_no2, 'dd_no2' => $dd_no2, 'dd_date2' => $dd_date2, 'dd_bank2' => $dd_bank2, 'online_date2' => $online_date2, 'paytm_ref_no2' =>$ref_no1, 'paytm_online_date2' =>$paytm_date1, 'upi_ref_no2' =>$upi_ref_no1, 'upi_online_date2' =>$upi_date1, 'tsv' => $tsv, 'tsv_per_sft_rs' => $per_sqft, 'land_owner_rate' => $land_owner_rate, 'land_owner_amount' => $land_owner_amount, 'gss_rate' => $gss_rate, 'gss_amount' => $gss_amount, 'reg_date_type' => $reg_date_type, 'sales_agreement_due_date' => $sale_agree_date, 'sales_agreement_due_amount' => $sale_agree_amount, 'registration_due_date' => $reg_due_date, 'registration_due_amount' => $reg_due_amount, 'site_number' => $site_number, 'dimension' => $site_dimension, 'application_scan' => $application_scan, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ); $where_installment = array('installment_id'=>$installment_id); $where_detail = array('detail_id'=>$detail_id); $instal_data = array( 'booking_id' => $booking_id, 'booking_detal_id' => $detail_id, 'installment_due_date' => $instal_due_date, 'installment_due_amount' => $instal_due_amount, 'payment_mode' => $payment_type ); $total = 0; if($instal_due_amount == 0 || $instal_due_amount == "") { $total = $booking_amount1 + $booking_amount2 + $reg_due_amount + $sale_agree_amount; } else { $total = $booking_amount1 + $booking_amount2 + $instal_due_amount + $reg_due_amount + $sale_agree_amount; } if($total > $tsv || $total < $tsv) { return $this->response->setJSON(['result'=>2,'message'=>"Not matching TSV"]); } else { $instal_result = $gss_model->update1($instal_table,$where_installment,$instal_data); $detail_result = $gss_model->update1($detail_table,$where_detail,$detail_data); if ($db->affectedRows() > 0) { $gss_model->update1($booking_table,$where_booking,$booking_data); //-------------------------------------------------------------------------------------// $notification_table = 'gss_commission_notifications'; $check_associate = $gss_model->get_where_row($booking_table,$where_booking); if($check_associate->associate != 0) { $notifications = $gss_model->check_notification($booking_id,$detail_id); if($notifications) { } else { $payment_table = 'gss_plot_payments'; $check_amounts = $gss_model->get_where_row($payment_table,$where_booking); //print_r($check_amounts);die(); if(!empty($check_amounts->agreement_amount)) { $commission_agreement = 'Available'; } else { $commission_agreement = "Not Available"; } if(!empty($check_amounts->registration_amount)) { $commission_registration = 'Available'; } else { $commission_registration = "Not Available"; } $notification_data = array( 'booking_id' => $booking_id, 'detail_id' => $detail_id, 'commission_agreement' => $commission_agreement, 'commission_registration' => $commission_registration, 'status' => 'PENDING' ); $commission_result = $gss_model->insert1($notification_table,$notification_data); } } return $this->response->setJSON(['result' => 1,'message' => "Updated successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); } } } public function submanagement_list() { $id = $this->request->getGet('id'); $db = \Config\Database::connect(); $builder = $db->table('gss_management A'); $builder->select('A.*, B.*, C.*, D.*, A.created_at as commission_date'); $builder->join('gss_bookings B', 'B.booking_id = A.booking_id'); $builder->join('gss_booking_details C', 'C.detail_id = A.detail_id'); $builder->join('gss_new_projects D', 'D.project_id = B.project_id'); $builder->where('A.delete_status', 'ACTIVE'); $builder->where('B.delete_status', 'ACTIVE'); $builder->where('C.delete_status', 'ACTIVE'); $builder->where('D.delete_status', 'ACTIVE'); $builder->where('A.management_id', $id); $builder->groupBy('A.booking_id'); $builder->orderBy('A.management_id', 'DESC'); $result = $builder->get()->getResult(); $array = []; $data = []; foreach ($result as $val) { $data['booking_id'] = $val->booking_id; $data['commission_date'] = $val->commission_date; $data['management_id'] = $val->management_id; $data['project_name'] = $val->project_name; $data['site_number'] = $val->site_number; $data['total_commission_perc'] = $val->subtotal_commission_perc; $data['total_commission_rs'] = $val->subtotal_commission_rs; // Subassociate details $subBuilder = $db->table('gss_brokers A'); $subBuilder->select('A.*'); $subBuilder->where('A.delete_status', 'ACTIVE'); $subBuilder->where('A.broker_id', $val->subassociate); $subResult = $subBuilder->get()->getRow(); $data['subassociate'] = $subResult ? $subResult->associate_name : ''; // Agreement data $agreeBuilder = $db->table('gss_management A'); $agreeBuilder->select('A.management_id, A.subagreement_executed_on, A.subpayment_on_agreement, A.agreement_status'); $agreeBuilder->where('A.delete_status', 'ACTIVE'); $agreeBuilder->where('A.booking_id', $val->booking_id); $result1 = $agreeBuilder->get()->getRow(); $data['payment_on_agreement'] = !empty($result1->subpayment_on_agreement) ? $result1->subpayment_on_agreement : ''; $data['agreement_executed_on'] = !empty($result1->subagreement_executed_on) ? $result1->subagreement_executed_on : ''; // Registration data $regBuilder = $db->table('gss_management A'); $regBuilder->select('A.management_id, A.subpayment_on_registration, A.subregistration_on, A.registration_status'); $regBuilder->where('A.delete_status', 'ACTIVE'); $regBuilder->where('A.booking_id', $val->booking_id); $result2 = $regBuilder->get()->getRow(); $data['payment_on_registration'] = $result2->subpayment_on_registration ?? ''; $data['registration_on'] = $result2->subregistration_on ?? ''; $array[] = $data; } if (!empty($array)) { return $this->response->setJSON($array); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No data available']); } } }?>