EVOLUTION-NINJA
Edit File: Accounts.php
<?php namespace App\Controllers; use App\Models\Gss_model; class Accounts extends BaseController { 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 reminders() { $admin_id = session()->get('admin_id'); if($admin_id) { $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/reminders',$data); } else { redirect('/'); } } public function accounts() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $result['accounts'] = $gss_model->account_management_list(); $result['user_type_id'] = $this->access_id(); $result['access'] = $this->access_details(); return view('admin/accounts',$result); } else { redirect('/'); } } //Account Management list public function account_management_list() { $gss_model=new Gss_model(); $result = $gss_model->account_management_list(); if($result) { echo json_encode(array('result'=>1,'management_list'=>$result)); } else { echo json_encode(array('result'=>0,'message'=>"No data available")); } } //Commission details 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('/'); } } //Commission payment public function commission_payment() { $gss_model=new Gss_model(); $table = 'gss_commission_payments'; $mgnt_table = 'gss_management'; $booking_id = $this->request->getpost('management_id'); $order_by = 'payment_id'; $where_booking = array('booking_id' => $booking_id,'delete_status' => 'ACTIVE'); $id_result = $gss_model->get_where_row($mgnt_table,$where_booking); $management_id = $id_result->management_id; $where = array('management_id'=>$management_id,'delete_status'=>'ACTIVE'); $result = $gss_model->get_where_row_orderby($table,$where,$order_by); if($result) { return $this->response->setJSON(['result'=>1,'commission_payment'=>$result]); } else { return $this->response->setJSON(['result'=>0,'message'=>"No data available"]); } } public function add_commission_payment() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $table = 'gss_commission_payments'; $mgnt_table = 'gss_management'; $booking_id = $this->request->getpost('management_id'); $payment_type = $this->request->getpost('payment_type'); $commission_type = $this->request->getpost('commission_type'); $amount = $this->request->getpost('amount'); $tds = $this->request->getpost('tds'); $without_tax = $amount*$tds/100; $with_tax = $amount - $without_tax; $cheque_no = ''; $cheque_date = ''; $bank_name = ''; $utr_no = ''; $online_date = ''; $dd_no = ''; $dd_date = ''; $dd_bank = ''; $cash_date = ''; $payment_date =''; $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); if($payment_type == 'Cheque') { $cheque_no = $this->request->getpost('check_no'); $cheque_date = $this->request->getpost('check_date'); if($cheque_date != "") { $date = new \DateTime($cheque_date); $cheque_date = $date->format('Y-m-d'); $payment_date= $date->format('Y-m-d'); } $bank_name = $this->request->getpost('bank_name'); } else if($payment_type == 'Online') { $utr_no = $this->request->getpost('utr_no'); $online_date = $this->request->getpost('online_date'); if($online_date != "") { $date = new \DateTime($online_date); $online_date = $date->format('Y-m-d'); $payment_date = $date->format('Y-m-d'); } } else if($payment_type == 'DD') { $dd_no = $this->request->getpost('dd_no'); $dd_date = $this->request->getpost('dd_date'); if($dd_date != "") { $date = new \DateTime($dd_date); $dd_date = $date->format('Y-m-d'); $payment_date = $date->format('Y-m-d'); } $dd_bank = $this->request->getpost('dd_bank'); } else if($payment_type == 'Cash') { $cheque_date = $this->request->getpost('cash_date'); if($cheque_date != "") { $date = new \DateTime($cheque_date); $cheque_date = $date->format('Y-m-d'); $payment_date = $date->format('Y-m-d'); } } $where_booking = ['booking_id' => $booking_id,'delete_status' => 'ACTIVE']; $id_result = $gss_model->get_where_row($mgnt_table,$where_booking); $management_id = $id_result->management_id ?? null; $data = [ 'management_id' => $management_id, 'commission_type' => $commission_type, 'payment_type' => $payment_type, 'tds' => $tds, 'amount' => $amount, 'with_tax' => $with_tax, 'cheque_no' => $cheque_no, 'cheque_date' => $cheque_date, 'utr_no' => $utr_no, 'online_date' => $online_date, 'dd_no' => $dd_no, 'dd_date' => $dd_date, 'dd_bank' => $dd_bank, 'bank_name' => $bank_name, 'payment_date' => $payment_date, 'delete_status' => 'ACTIVE', 'created_at' => $created_at ]; $where = ['management_id' => $management_id,'delete_status' => 'ACTIVE']; $management = $gss_model->get_where_row($mgnt_table,$where); $payments = $gss_model->get_where_result($table,$where); $total_commn = $management->total_commission_rs ?? 0; $paid_amount = 0; foreach($payments as $val) { (float)$paid_amount += (float)$val->amount; } $total_amount = (float) $paid_amount + (float) $amount; if($total_amount > $total_commn) { return $this->response->setJSON(['result'=>2,'message'=>"Commission amount exceeded"]); } else if($payment_type == "") { return $this->response->setJSON(['result'=>3,'message'=>"Select payment type"]); } else if($commission_type == "") { return $this->response->setJSON(['result'=>4,'message'=>"Select commission type"]); } else { $result = $gss_model->insert1($table,$data); if($result) { $whr_mgnt = array('management_id'=>$management_id); $data = $gss_model->get_where_result($table,$whr_mgnt); if($data) { $agr_array = array(); $regn_array = array(); foreach($data as $val) { array_push($agr_array, $val->commission_type); array_push($regn_array, $val->commission_type); } if(in_array('Agreement',$agr_array) || in_array('Registration',$regn_array)) { $where1 = array('management_id'=>$management_id); $table1 = 'gss_management'; $final_status = array('final_status'=>'APPROVED'); $final_update = $gss_model->update1($table1,$where1,$final_status); } } return $this->response->setJSON(['result'=>1,'message'=>"Added successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong"]); } } } public function accounts_notifications() { $gss_model=new Gss_model(); $result = $gss_model->accounts_notifications(); if($result) { return $this->response->setJSON(['result'=>1,'notifications'=>$result,'total'=>count($result)]); } else { return $this->response->setJSON(['result'=>0]); } } public function edit_subcommission_payment() { $gss_model=new Gss_model(); $table = 'gss_sub_commission_payments'; $payment_id = $this->request->getpost('subpayment_id'); $where = array('sub_payment_id'=>$payment_id,'delete_status'=>'ACTIVE'); $result = $gss_model->get_where_row($table,$where); if($result) { return $this->response->setJSON(['commission_details'=>$result,'result'=>1]); } else { return $this->response->setJSON(['result'=>0]); } } public function edit_commission_payment() { $gss_model=new Gss_model(); $table = 'gss_commission_payments'; $payment_id = $this->request->getpost('payment_id'); $where = array('payment_id'=>$payment_id,'delete_status'=>'ACTIVE'); $result = $gss_model->get_where_row($table,$where); if($result) { return $this->response->setJSON(['commission_details'=>$result,'result'=>1]); } else { return $this->response->setJSON(['result'=>0]); } } //Update commission payment public function update_commission_payment() { $gss_model=new Gss_model(); $table = 'gss_commission_payments'; $mgnt_table = 'gss_management'; $management_id = $this->request->getpost('management_id1'); $payment_id = $this->request->getpost('payment_id1'); $payment_type = $this->request->getpost('payment_type1'); $commission_type = $this->request->getpost('commission_type1'); $amount = $this->request->getpost('amount1'); $tds = $this->request->getpost('tds1'); $without_tax = $amount*$tds/100; $with_tax = $amount - $without_tax; $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $cash_date = ''; $cheque_no = ''; $cheque_date = ''; $bank_name = ''; $utr_no = ''; $online_date = ''; $dd_no = ''; $dd_date = ''; $dd_bank = ''; $payment_date =''; if($payment_type == 'Cheque') { $cheque_no = $this->request->getpost('check_no1'); $cheque_date = $this->request->getpost('check_date1'); if($cheque_date != "") { $date = new \DateTime($cheque_date); // ✅ Use global DateTime class $cheque_date = $date->format('Y-m-d'); $payment_date = $date->format('Y-m-d'); } $bank_name = $this->request->getpost('bank_name1'); } else if($payment_type == 'Online') { $utr_no = $this->request->getpost('utr_no1'); $online_date = $this->request->getpost('online_date1'); if($online_date != "") { $date = new \DateTime($online_date); $online_date = $date->format('Y-m-d'); $payment_date= $date->format('Y-m-d'); } } else if($payment_type == 'DD') { $dd_no = $this->request->getpost('dd_no1'); $dd_date = $this->request->getpost('dd_date1'); if($dd_date != "") { $date = new \DateTime($dd_date); $dd_date = $date->format('Y-m-d'); $payment_date = $date->format('Y-m-d'); } $dd_bank = $this->request->getpost('dd_bank1'); } else if($payment_type == 'Cash') { $cheque_date = $this->request->getpost('cash_date1'); if($cheque_date != "") { $date = new \DateTime($cheque_date); $cheque_date = $date->format('Y-m-d'); $payment_date = $date->format('Y-m-d'); } } $data = array( 'management_id' => $management_id, 'commission_type' => $commission_type, 'payment_type' => $payment_type, 'tds' => $tds, 'amount' => $amount, 'with_tax' => $with_tax, 'cheque_no' => $cheque_no, 'cheque_date' => $cheque_date, 'utr_no' => $utr_no, 'online_date' => $online_date, 'dd_no' => $dd_no, 'dd_date' => $dd_date, 'dd_bank' => $dd_bank, 'bank_name' => $bank_name, 'payment_date' => $payment_date, 'delete_status' => 'ACTIVE', 'updated_at' => $created_at ); // print_r($data); // die(); $where = array('payment_id'=>$payment_id); $result = $gss_model->update1($table,$where,$data); $db = \Config\Database::connect(); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result'=>1,'message'=>"Updated successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong"]); } } public function delete_commission_payment() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $table = 'gss_commission_payments'; $payment_id = $this->request->getpost('payment_id'); $where = array('payment_id'=>$payment_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 incentive_form() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $broker_table = 'gss_brokers'; $where_reference = array('delete_status'=>'ACTIVE','type'=>'Executives'); $where_logistics = array('delete_status'=>'ACTIVE','type'=>'Logistic'); $associate_order_by = 'associate_name'; $data['logistics'] = $gss_model->get_where_result_orderby_asc($broker_table,$where_logistics,$associate_order_by); $data['reference'] = $gss_model->get_where_result_orderby_asc($broker_table,$where_reference,$associate_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/incentive',$data); } else { redirect('/'); } } public function executive_incentive() { $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'); } $executive = $_GET['reference']; $result = $gss_model->get_executive_incentives($from_date,$to_date,$executive); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function shared_to_executive_incentive() { $gss_model=new Gss_model(); $from_date = $_GET['from_date']; if($from_date != "") { $date = new \DateTime($from_date); // Create a DateTime object from the provided date string $from_date = $date->format('Y-m-d'); // Format the date into 'YYYY-MM-DD' format } $to_date = $_GET['to_date']; if($to_date != "") { $date = new \DateTime($to_date); $to_date = $date->format('Y-m-d'); } $executive = $_GET['reference']; $result = $gss_model->get_shared_executive_incentives($from_date,$to_date,$executive); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function shared_to_logistic_incentive() { $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'); } $logistic = $_GET['reference']; $result = $gss_model->get_shared_logistic_incentives($from_date,$to_date,$logistic); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function pending_logistic_incentive() { $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'); } $executive = $_GET['reference']; $result = $gss_model->get_pending_logistic_incentives($from_date,$to_date,$executive); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function selected_executive_incentive() { $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'); } $executive = $_GET['reference']; $result = $gss_model->get_selected_executive_incentives($from_date,$to_date,$executive); if(!empty($result)) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function logistic_incentive() { $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'); } $executive = $_GET['reference']; $result = $gss_model->get_logistic_incentives($from_date,$to_date,$executive); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function update_shared_logistic() { $db = \Config\Database::connect(); $gss_model=new Gss_model(); $booking_id = $this->request->getpost('booking_id'); $shared_between_log = $this->request->getpost('logistics_ids'); $shared_log_amount = $this->request->getpost('shared_log_amount'); $table = "gss_booking_details"; $where = array('booking_id'=>$booking_id); $data = array('shared_between_logistic'=>$shared_between_log,'shared_logistic_amount'=>$shared_log_amount); $result = $gss_model->update1($table,$where,$data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result'=>1,'message'=>'Added!']); } else { return $this->response->setJSON(['result'=>0]); } } public function get_logistics() { $broker_id = $this->request->getPost('broker_id'); // Use getPost() (case-sensitive) $broker_table = 'gss_brokers'; $associate_order_by = 'associate_name'; // Define conditions $where_logistics = [ 'delete_status' => 'ACTIVE', 'type' => 'Logistic' ]; // Exclude the given broker_id if (!empty($broker_id)) { $where_logistics['broker_id !='] = $broker_id; } // Database query $db = \Config\Database::connect(); $builder = $db->table($broker_table); $builder->select('*'); $builder->where($where_logistics); $builder->orderBy($associate_order_by, 'ASC'); $query = $builder->get(); $result = $query->getResult(); // Fetch multiple rows as objects // Return JSON response if (!empty($result)) { return $this->response->setJSON(['result' => 1, 'logistics' => $result]); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No logistics found']); } } public function sixty_perc_executive_incentive() { $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'); } $executive = $_GET['reference']; $result = $gss_model->get_sixty_perc_executive_incentive($from_date,$to_date,$executive); if(!empty($result)) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function get_sixty_percentage_total_amount() { $gss_model=new Gss_model(); $sixty_amount = $this->request->getpost('sixty_amount'); if(!empty($sixty_amount)) { $sixty_total = 0; foreach ($sixty_amount as $keys => $values) { $sixty_amounts = $values; if(!empty($sixty_amounts)) { $sixty_total+=$sixty_amounts; } } } else { $sixty_total = 0; } if($sixty_total != "0") { return $this->response->setJSON(['result'=>1,'sixty_percent_amount'=>$sixty_total]); } else { return $this->response->setJSON(['result'=>0]); } } public function get_fourty_percentage_total_amount() { $fourty_amount = $this->request->getpost('fourty_amount'); if(!empty($fourty_amount)) { $total = 0; foreach ($fourty_amount as $keys => $values) { $fourty_amounts = $values; if(!empty($fourty_amounts)) { $total+=$fourty_amounts; } } } else { $total = 0; } if($total!='0') { return $this->response->setJSON(['result'=>1,'fourty_percent_amount'=>$total]); } else { return $this->response->setJSON(['result'=>0]); } } public function paidpending_executive_incentive() { $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'); } $executive = $_GET['reference']; $result = $gss_model->get_paidpending_executive_incentives($from_date,$to_date,$executive); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function get_total_sqft() { $gss_model=new Gss_model(); $fourty_booking_id = explode(",",$this->request->getpost('fourty_booking_id')); $sixty_booking_id = explode(",",$this->request->getpost('sixty_booking_id')); $both_booking_id = explode(",",$this->request->getpost('both_booking_id')); $final_booking_ids = array_merge($fourty_booking_id,$sixty_booking_id,$both_booking_id); $ids = array_unique($final_booking_ids); $total_sqft=0; foreach($ids as $key=>$booking_ids) { if(!empty($booking_ids)) { $details=$gss_model->get_total_sites_sqft_booked($booking_ids); if($details) { $total_sqft+=$details->dimension; } } } if($total_sqft) { // return $this->response->setJSON(['result'=>1,'message'=> $total_sqft]); return $this->response->setJSON(['result' => 1, 'message' => 'Submitted', 'total_sqft' => $total_sqft]); } else { return $this->response->setJSON(['result'=>0,'message'=>'Not found']); } } public function get_insentive_details() { $gss_model=new Gss_model(); $booking_id = $this->request->getpost('booking_id'); $reference = $this->request->getpost('reference'); $table_reference ='gss_booking_details'; $where_reference = array('shared_between_executive'=>$reference,'booking_id'=>$booking_id); $get_reference = $gss_model->get_where_row($table_reference,$where_reference); if(empty($get_reference)) { $calc_table = 'gss_incentive_reports'; $where_booking = array('booking_id'=>$booking_id); $inc_data = $gss_model->get_where_row($calc_table,$where_booking); if($inc_data) { return $this->response->setJSON(['result'=> 1,'data' => $inc_data,'executive'=>'executive1']); } else { return $this->response->setJSON(['result'=> 0]); } } else { $calc_table = 'gss_incentive_reports'; $where_booking = array('booking_id2'=>$booking_id); $inc_data = $gss_model->get_where_row($calc_table,$where_booking); if($inc_data) { return $this->response->setJSON(['result'=> 1,'data' => $inc_data,'executive'=>'executive2']); } else { return $this->response->setJSON(['result'=> 0]); } } } public function update_incentive_calculation() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $admin_id = session()->get('admin_id'); $reference = $this->request->getpost('edit_calc_reference'); $booking_id = $this->request->getpost('edit_calc_booking_id'); $total_sqft = $this->request->getpost('edit_calc_total_sqft'); $rate_per_sqft = $this->request->getpost('edit_calc_rate_per_sqft'); $total_amount_fixed = $this->request->getpost('edit_calc_total_amount_fixed'); $total_amount_fixed = str_replace(',', '', $total_amount_fixed); $incentive_on_agmnt = $this->request->getpost('edit_calc_incentive_on_agmnt'); $incentive_on_agmnt = str_replace(',', '', $incentive_on_agmnt); $incentive_on_regn = $this->request->getpost('edit_calc_incentive_on_regn'); $incentive_on_regn = str_replace(',', '', $incentive_on_regn); $insentive_perc = $this->request->getpost('edit_calc_insentive_perc'); $balance = $this->request->getpost('edit_calc_balance'); $balance = str_replace(',', '', $balance); $source = $this->request->getpost('edit_calc_source'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $calc_table = 'gss_incentive_reports'; $update_data = array( 'total_sqft' => $total_sqft, 'rate_per_sqft' => $rate_per_sqft, 'total_amount_fixed' => $total_amount_fixed, 'incentive_on_agmnt' => $incentive_on_agmnt, 'incentive_on_regn' => $incentive_on_regn, // 'insentive_perc' => $insentive_perc, 'balance' => $balance, 'source' => $source, 'updated_at' => $created_at ); if($insentive_perc == '40%') { $update_data['insentive_perc'] = $insentive_perc; $update_data['insentive_perc_both'] = ""; $update_data['insentive_perc_sixty'] = ""; } else if($insentive_perc == '60%') { $update_data['insentive_perc'] = ""; $update_data['insentive_perc_sixty'] = $insentive_perc; $update_data['insentive_perc_both'] = ""; } else { $update_data['insentive_perc_both'] = $insentive_perc; $update_data['insentive_perc_sixty'] = ""; $update_data['insentive_perc'] = ""; } $where_booking = array('booking_id'=>$booking_id); $update_result = $gss_model->update1($calc_table,$where_booking,$update_data); 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"]); } } public function delete_executive_incentives() { $db = \Config\Database::connect(); $gss_model = new Gss_model(); $booking_id = $this->request->getPost('booking_id'); // Soft delete from gss_incentive_reports $table1 = "gss_incentive_reports"; $where1 = ['booking_id' => $booking_id]; $data1 = ['delete_status' => "ACTIVE"]; // ✅ Don't clear booking_id unless required $update1 = $gss_model->update1($table1, $where1, $data1); // Reset status in gss_booking_details $table2 = "gss_booking_details"; $where2 = ['booking_id' => $booking_id]; $data2 = ['selected_incentive_status' => '']; $update2 = $gss_model->update1($table2, $where2, $data2); if ($update1 || $update2) { return $this->response->setJSON(['result' => 1, 'message' => 'Deleted Successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No rows updated.']); } } public function get_executives() { // Load the database connection $db = \Config\Database::connect(); $broker_id = $this->request->getPost('broker_id'); $broker_table = 'gss_brokers'; $associate_order_by = 'associate_name'; $where_logistics = array('delete_status' => 'ACTIVE', 'type' => 'Executives', 'broker_id !=' => $broker_id); // Use the $db object to perform database operations $builder = $db->table($broker_table); // Use table() method instead of from() $builder->select('*') // Equivalent to $this->db->select('*'); ->where($where_logistics) // Equivalent to $this->db->where($where_logistics); ->orderBy($associate_order_by, "ASC"); // Equivalent to $this->db->order_by($associate_order_by, "ASC") $query = $builder->get(); // Executes the query and returns the result $result = $query->getResult(); // Fetch the results if ($result) { return $this->response->setJSON(['result' => 1, 'executives' => $result]); } else { return $this->response->setJSON(['result' => 0]); } } public function update_shared_executive() { $db = \Config\Database::connect(); $gss_model=new Gss_model(); $booking_id = $this->request->getpost('exe_booking_id'); $shared_between_exe = $this->request->getpost('executive_ids'); $shared_to_exe = $this->request->getpost('shared_exe_to'); $shared_exe_amount = $this->request->getpost('shared_total_amount'); $shared_amount = $this->request->getpost('shared_total_amount'); $shared_percentage = $this->request->getpost('shared_exe_percent'); /* if($shared_exe_amount == 0) { $shared_amount = 0; } else { $shared_percentage = 0; }*/ $table = "gss_booking_details"; $where = array('booking_id'=>$booking_id); $data = array('shared_from_executive'=>$shared_to_exe,'shared_between_executive'=>$shared_between_exe,'shared_executive_amount'=>$shared_amount,'shared_executive_percentage'=>$shared_percentage,'shared_amount'=>$shared_exe_amount); $result = $gss_model->update1($table,$where,$data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result'=>1,'message'=>'Added!']); } else { return $this->response->setJSON(['result'=>0]); } } public function get_both_total_amount() { $fourty_amount = $this->request->getpost('fourty_amount'); $sixty_amount = $this->request->getpost('sixty_amount'); $total1 = 0; foreach ($fourty_amount as $keys => $values) { $fourty_amounts = $values; if(!empty($fourty_amounts)) { $total1+=$fourty_amounts; } } $total2 = 0; foreach ($sixty_amount as $keys => $values) { $sixty_amounts = $values; if(!empty($sixty_amounts)) { $total2+=$sixty_amounts; } } $both_amount = $total1+$total2; if(!empty($both_amount)) { return $this->response->setJSON(['result'=>1,'both_amount'=>$both_amount]); } else { return $this->response->setJSON(['result'=>0]); } } public function selected_logistic_incentive() { $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'); } $executive = $_GET['reference']; $result = $gss_model->get_selected_logistic_incentives($from_date,$to_date,$executive); //print_r($result); die(); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function add_executive_incentive() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $table = 'gss_executive_incentives_reports'; $array1 = array(); $broker_id = $this->request->getpost('broker_id'); $fourty_broker_id = $this->request->getpost('fourty_broker_id'); $sixty_project_id = explode(",",$this->request->getpost('sixty_project_id')); $fourty_project_id = explode(",",$this->request->getpost('fourty_project_id')); $both_project = explode(",",$this->request->getpost('both_project_id')); $total_project_id = array_merge($fourty_project_id,$sixty_project_id,$both_project); $fourty_site_number = explode(",",$this->request->getpost('fourty_site_number')); $sixty_site_number = explode(",",$this->request->getpost('sixty_site_number')); $both_site_number = explode(",",$this->request->getpost('both_site_number')); $total_site_num = array_merge($fourty_site_number,$sixty_site_number,$both_site_number); foreach ($total_project_id as $keys => $values) { $project_ids = $values; if(!empty($project_ids)) { $res['project_id']=$total_project_id[$keys]; $res['site_number']=$total_site_num[$keys]; $res['executive']=$fourty_broker_id; array_push($array1,$res); } else { $projects_sites_ids= ""; } } $projects_sites_ids= json_encode($array1); $total_sqft = $this->request->getpost('total_sqft'); $basic_target = $this->request->getpost('basic_target'); $duration = $this->request->getpost('duration'); $total_target = $this->request->getpost('total_target'); $achieved = $this->request->getpost('achieved'); $cancelled = $this->request->getpost('cancelled'); $excess = $this->request->getpost('excess'); $shortage = $this->request->getpost('shortage'); $net_achieved = $this->request->getpost('net_achieved'); $net_amt = $this->request->getpost('net_amt'); $amount = $this->request->getpost('amount'); $payment_type1 = $this->request->getpost('payment_type1'); if($payment_type1 == "Cheque") { $cheque_number = $this->request->getpost('check_no1'); $cheque_date = $this->request->getpost('check_date1'); $cheque_amount = $this->request->getpost('cheque_amount'); $bank_name = $this->request->getpost('bank_name1'); $utr_number = ""; $online_date = "00-00-0000"; $cash_amount = ""; $cash_date = "00-00-0000"; $neft_cheque = ""; $neft_cheque_amt = ""; } else if($payment_type1 == "Cash") { $cash_amount = $this->request->getpost('cash_amount'); $cash_date = $this->request->getpost('cash_date'); $cheque_date = "00-00-0000"; $bank_name = ""; $cheque_number = ""; $utr_number = ""; $neft_cheque = ""; $neft_cheque_amt = ""; $online_date = "00-00-0000"; $cheque_amount = ""; } else if($payment_type1 == "Online Payment") { $utr_number = $this->request->getpost('vtr_no1'); $online_date = $this->request->getpost('online_date1'); $neft_cheque = $this->request->getpost('neft_cheque'); $neft_cheque_amt = $this->request->getpost('neft_cheque_amt'); $cheque_date = "00-00-0000"; $bank_name = ""; $cheque_number = ""; $cash_amount = ""; $cash_date = "00-00-0000"; $cheque_amount = ""; } $fourty_booking_id = explode(",",$this->request->getpost('fourty_booking_id')); $sixty_booking_id = explode(",",$this->request->getpost('sixty_booking_id')); $both_booking_id = explode(",",$this->request->getpost('both_booking_id')); $final_booking_ids = array_merge($fourty_booking_id,$sixty_booking_id,$both_booking_id); $booking_ids = array_unique($final_booking_ids); $exe_remark = $this->request->getpost('exe_remark'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); foreach ($total_project_id as $keys => $values) { if(!empty($values)) { $data = array('broker_id'=>$fourty_broker_id, 'projects_sites'=>$projects_sites_ids, 'total_sqft'=>$total_sqft, 'basic_target'=>$basic_target, 'duration' =>$duration, 'total_target' =>$total_target, 'achieved'=>$achieved, 'cancelled'=>$cancelled, 'excess'=>$excess, 'shortage'=>$shortage, 'net_achieved'=>$net_achieved, 'net_amt'=>$net_amt, 'amount'=>$amount, 'payment_type'=>$payment_type1, 'cheque_number'=>$cheque_number, 'cheque_date'=>$cheque_date, 'cheque_amount'=>$cheque_amount, 'bank_name'=>$bank_name, 'cash_amount'=>$cash_amount, 'cash_date'=>$cash_date, 'utr_number'=>$utr_number, 'online_date'=>$online_date, 'neft_cheque'=>$neft_cheque, 'neft_cheque_amt'=>$neft_cheque_amt, 'exe_remark'=>$exe_remark, 'delete_status'=>'ACTIVE', 'created_at'=>$created_at, 'project_id'=>$total_project_id[$keys], 'site_number'=>$total_site_num[$keys], 'executive_id'=>$fourty_broker_id, ); $result = $gss_model->insert1($table,$data); } } foreach ($final_booking_ids as $key => $value) { $id = json_decode($value); if(!empty($id)) { $table_reference ='gss_booking_details'; $where_reference = array('shared_between_executive'=>$fourty_broker_id,'booking_id'=>$id); $get_reference = $gss_model->get_where_row($table_reference,$where_reference); if(empty($get_reference)) { $where = array('booking_id'=>$id,'delete_status'=>'ACTIVE'); $table = "gss_incentive_reports"; $get_row = $gss_model->get_where_row($table,$where); if(!empty($get_row)) { if($get_row->balance == "0" || $get_row->balance == "00" || $get_row->balance == "0.0") { $update_booking_datas['selected_incentive_status'] = "YES"; } else { $update_booking_datas['selected_incentive_status'] = ""; } } else { $update_booking_datas['selected_incentive_status'] = ""; } } else { $where = array('booking_id2'=>$id,'delete_status'=>'ACTIVE'); $table = "gss_incentive_reports"; $get_row = $keysgss_model->get_where_row($table,$where); if(!empty($get_row)) { if($get_row->balance == "0" || $get_row->balance == "00" || $get_row->balance == "0.0") { $update_booking_datas['selected_incentive_status2'] = "YES"; } else { $update_booking_datas['selected_incentive_status2'] = ""; } } else { $update_booking_datas['selected_incentive_status2'] = ""; } } $tble_sites='gss_new_sites'; $condition_sites=array('project_id'=>$total_project_id[$key],'site_number'=>$total_site_num[$key]); $update_data=array('incentive_status'=>"YES"); $gss_model->update1($tble_sites,$condition_sites,$update_data); $tble_bookings_details='gss_booking_details'; $condition_bookings=array('booking_id'=>$id); $gss_model->update1($tble_bookings_details,$condition_bookings,$update_booking_datas); } } $fourty_status = $this->request->getpost('fourty_status'); $sixty_status = $this->request->getpost('sixty_status'); $both_status = $this->request->getpost('both_status'); if($fourty_status !="") { $update_booking_data=array('fourty_status'=>$fourty_status); $update_booking_data2=array('fourty_status2'=>$fourty_status); $fourty_booking_id = explode(",",$this->request->getpost('fourty_booking_id')); foreach ($fourty_booking_id as $key => $value) { if(!empty($value)) { $table_reference ='gss_booking_details'; $where_reference = array('shared_between_executive'=>$fourty_broker_id,'booking_id'=>$value); $get_reference = $gss_model->get_where_row($table_reference,$where_reference); if(empty($get_reference)) { $table ='gss_incentive_reports'; $where_booking = array('booking_id'=>$value); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if ($get_booking_row && $get_booking_row->sixty_status != "") { $update_insentive_data['fourty_status'] = $fourty_status; $gss_model->update1($table, $where_booking, $update_insentive_data); } $condition_booking=array('booking_id'=>$value); $tble_booking_details='gss_booking_details'; $gss_model->update1($tble_booking_details,$condition_booking,$update_booking_data); } else { $table ='gss_incentive_reports'; $where_booking = array('booking_id2'=>$value); $get_booking_row = $this->gss_model->get_where_row($table,$where_booking); if($get_booking_row->sixty_status2 != "") { $update_insentive_data['fourty_status2'] = $fourty_status; $gss_model->update1($table,$where_booking,$update_insentive_data); } $condition_booking=array('booking_id'=>$value); $tble_booking_details='gss_booking_details'; $gss_model->update1($tble_booking_details,$condition_booking,$update_booking_data2); } } } } if($sixty_status !="") { $update_booking_data=array('sixty_status'=>$sixty_status); $update_booking_data2=array('sixty_status2'=>$sixty_status); $sixty_booking_id = explode(",",$this->request->getpost('sixty_booking_id')); foreach ($sixty_booking_id as $key => $value) { if(!empty($value)) { $table_reference ='gss_booking_details'; $where_reference = array('shared_between_executive'=>$fourty_broker_id,'booking_id'=>$value); $get_reference = $gss_model->get_where_row($table_reference,$where_reference); if(empty($get_reference)) { $table ='gss_incentive_reports'; $where_booking = array('booking_id'=>$value); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if($get_booking_row->fourty_status != "") { $update_insentive_data['sixty_status'] = $sixty_status; $gss_model->update1($table,$where_booking,$update_insentive_data); } $condition_booking=array('booking_id'=>$value); $tble_booking_details='gss_booking_details'; $gss_model->update1($tble_booking_details,$condition_booking,$update_booking_data); } else { $table ='gss_incentive_reports'; $where_booking = array('booking_id2'=>$value); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if($get_booking_row->fourty_status2 != "") { $update_insentive_data['sixty_status2'] = $sixty_status; $gss_model->update1($table,$where_booking,$update_insentive_data); } $condition_booking=array('booking_id'=>$value); $tble_booking_details='gss_booking_details'; $gss_model->update1($tble_booking_details,$condition_booking,$update_booking_data2); } } } } if ($both_status != "") { $update_booking_data = ['both_status' => $both_status]; $update_booking_data2 = ['both_status2' => $both_status]; $both_booking_id = explode(",", $this->request->getPost('both_booking_id')); $result = false; // ✅ Initialize $result before the loop foreach ($both_booking_id as $key => $value) { if (!empty($value)) { $table_reference = 'gss_booking_details'; $where_reference = ['shared_between_executive' => $fourty_broker_id, 'booking_id' => $value]; $get_reference = $gss_model->get_where_row($table_reference, $where_reference); $condition_booking = ['booking_id' => $value]; $tble_booking_details = 'gss_booking_details'; if (empty($get_reference)) { $result = $gss_model->update1($tble_booking_details, $condition_booking, $update_booking_data); } else { $result = $gss_model->update1($tble_booking_details, $condition_booking, $update_booking_data2); } } } } // ✅ Ensure $result exists before checking it if (!empty($result)) { return $this->response->setJSON(['result' => 1, 'message' => "Added successfully"]); } else { return $this->response->setJSON(['result' => 0, 'message' => "Something went wrong.. try again"]); } } public function delete_logistic_incentives() { $db = \Config\Database::connect(); $gss_model=new Gss_model(); $id = $this->request->getpost('id'); $project_id = $this->request->getpost('project_id'); $booking_id = $this->request->getpost('booking_id'); $site_number = $this->request->getpost('site_number'); $table = "gss_logistic_incentives"; $where = array('id'=>$id); $get_det = $gss_model->get_where_row($table,$where); $projects_sites = json_decode($get_det->projects_sites); $array = array(); foreach($projects_sites as $key=>$ps_det) { $p_project_id=explode(",",$ps_det->project_id); $p_site_number=explode(",",$ps_det->site_number); foreach($p_project_id as $keys=>$p_pro_id) { if($project_id == $p_pro_id && $site_number==$p_site_number[$keys]) { unset($p_project_id[$keys]); unset($p_site_number[$keys]); } } $p_project_ids=implode(",",$p_project_id); $p_site_numbers=implode(",",$p_site_number); $res['project_id']=$p_project_ids; $res['site_number']=$p_site_numbers; array_push($array,$res); } $encoded = json_encode($array); $data = array('projects_sites'=>$encoded); $result = $gss_model->update1($table,$where,$data); if ($db->affectedRows() > 0) { $table1 = "gss_booking_details"; $data1 = array('selected_incentive_status'=>''); $where1 = array('booking_id'=>$booking_id); $result = $gss_model->update1($table1,$where1,$data1); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result'=>1,'message'=>'Deleted!']); } else { return $this->response->setJSON(['result'=>0]); } } else { return $this->response->setJSON(['result'=>0]); } } public function tax_invoice_form() { $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $table='gss_new_projects'; $data['project_names']=$gss_model->get_where_results_project_name(); $table ='gss_bank_details'; $where = array('delete_status'=>'ACTIVE'); $data['bank_details']=$gss_model->get_all_bank_details($table,$where); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/tax_invoice_form',$data); } else { redirect('/'); } } public function proforma_invoice_form() { $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $table='gss_new_projects'; $data['project_names']=$gss_model->get_where_results_project_name(); $table ='gss_bank_details'; $where = array('delete_status'=>'ACTIVE'); $data['bank_details']=$gss_model->get_all_bank_details($table,$where); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/proforma_invoice_form',$data); } else { redirect('/'); } } public function convert_invoice() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $table = 'gss_invoice_details'; $id = $this->request->getpost('id'); $wheres = array('id'=>$id); $datas=$gss_model->get_where_row($table,$wheres); $holder=$datas->bank_name; $invoice = $gss_model->get_tax_id($holder); if (!$invoice || empty($invoice->invoice_number)) { return $this->response->setJSON(['result' => 0, 'message' => 'No tax invoice found for this holder']); } $inv = (int)$invoice->invoice_number + 1; // ✅ Convert to integer safely $where = array('id'=>$id,'tax_status'=>0); $data = array('invoice_type'=>'Tax Invoice','tax_status'=>1,'invoice_number'=>$inv); $result = $gss_model->update1($table,$where,$data); if ($db->affectedRows() > 0) { $table = 'gss_invoice_details'; $where = array('id'=>$id,'tax_status'=>1,'invoice_number'=>$inv); $data=$gss_model->get_where_row($table,$where); $site_numbers = $data->site_numbers; $project_name=$data->project_id; $invoice_number=$data->invoice_number; //$explode= explode(",",$site_numbers); $data1=substr($site_numbers, 2, -2); $exp=array(); $path = explode(",", $data1); $exp = array_merge($exp, $path); foreach ($exp as $keys => $values) { $tble_sites='gss_new_sites'; $condition_sites=array('project_id'=>$project_name,'site_number'=>$values); $update_data=array('billing_status'=>'Tax Invoice','invoice_no'=>$invoice_number); $gss_model->update1($tble_sites,$condition_sites,$update_data); } return $this->response->setJSON(['result'=>1,'message'=>'Converted successfully']); } else { return $this->response->setJSON(['result' => 0, 'message' => 'No tax invoice found for this holder']); } } public function delete_invoice() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $table = 'gss_invoice_details'; $id = $this->request->getpost('id'); $tables = 'gss_invoice_details'; $wheres = array('id'=>$id); $data=$gss_model->get_where_row($tables,$wheres); $site_numbers = $data->site_numbers; $project_name=$data->project_id; $invoice_number=$data->invoice_number; //$explode= explode(",",$site_numbers); $data1=substr($site_numbers, 2, -2); $exp=array(); $path = explode(",", $data1); $exp = array_merge($exp, $path); foreach ($exp as $keys => $values) { $tble_sites='gss_new_sites'; $condition_sites=array('site_number'=>$values,'invoice_no'=>$invoice_number); $update_data=array('billing_status'=>'','invoice_no'=>0); $gss_model->update1($tble_sites,$condition_sites,$update_data); //echo $values; } $where = array('id'=>$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 tax_invoice_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'); } $holder_name = $_GET['holder_name']; $result = $gss_model->get_where_result_tax_invoice_list($from_date,$to_date,$holder_name); // print_r($result); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function proforma_invoice_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'); } $holder_name = $_GET['holder_name']; $result = $gss_model->get_where_result_proforma_invoice_list($from_date,$to_date,$holder_name); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function edit_tax_invoice_form() { $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $i=$_GET['id']; //$id=$this->input->post('id'); $table='gss_new_projects'; $data['project_names']=$gss_model->get_where_results_project_name(); $table= 'gss_bank_details' ; $where = array('delete_status'=>'ACTIVE'); $data['bank_name'] = $gss_model->get_all_bank_details($table,$where); $where1 = array('id'=>$i); $tab='gss_invoice_details'; $data['details']=$gss_model->get_where_row($tab,$where1); $data['invoice'] = $gss_model->get_tax_invoice_details($where1); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/edit_tax_invoice_form',$data); } else { redirect('/'); } } public function tax_invoice_print() { $gss_model=new Gss_model(); $uri = $_SERVER["REQUEST_URI"]; $val = substr($uri, strpos($uri, "=") + 1); $admin_id = session()->get('admin_id'); if($admin_id) { $id=$val; $data['details']=$gss_model->get_where_row_for_print($id); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/tax_invoice_print',$data); } else { redirect('/'); } } public function proforma_invoice_print() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $id=$_GET['id']; $table ='gss_bank_details'; $where = array('delete_status'=>'ACTIVE'); $data['bank_name'] = $gss_model->get_all_bank_details($table,$where); $data['details']=$gss_model->get_where_row_for_print($id); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/proforma_invoice_print',$data); } else { redirect('/'); } } public function get_row_details() { $gss_model=new Gss_model(); $table = 'gss_invoice_details'; $id = $this->request->getpost('id'); $where = array('id'=>$id); $result = $gss_model->get_where_row($table,$where); // print_r($result); // die(); if($result) { return $this->response->setJSON(['result'=>1,'message'=>$result]); } else { return $this->response->setJSON(['result'=>0,'message'=>'Not Found']); } } public function get_project_sites_edit() { $gss_model = new Gss_model(); $project_id = $this->request->getGet('project_id'); $inv = $this->request->getGet('inv'); // print_r($inv);die(); 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); 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 edit_proforma_invoice_form() { $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); if($admin_id) { $i=$_GET['id']; //$id=$this->input->post('id'); $table='gss_new_projects'; $data['project_names']=$gss_model->get_where_results_project_name(); $table= 'gss_bank_details' ; $where = array('delete_status'=>'ACTIVE'); $data['bank_name'] = $gss_model->get_all_bank_details($table,$where); $where1 = array('id'=>$i); $tab='gss_invoice_details'; $data['details']=$gss_model->get_where_row($tab,$where1); $data['invoice'] = $gss_model->get_proforma_invoice_details($where1); $data['user_type_id'] = $this->access_id(); $data['access'] = $this->access_details(); return view('admin/edit_proforma_invoice_form',$data); } else { redirect('/'); } } public function get_brokers_total_sites_sqft() { $gss_model=new Gss_model(); $project_id=$this->request->getpost('project_id'); $site_id=$this->request->getpost('site_id'); $booking_id=$this->request->getpost('booking_id'); $broker_id = $this->request->getpost('broker_id'); $total_sqft=0; $site_numbers=array(); $project_ids=array(); $executive_ids=array(); foreach($booking_id as $key=>$booking_ids) { $details=$gss_model->get_total_sites_sqft_booked($booking_ids); //$exe_details=$this->gss_model->get_total_sites_sqft_booked_executive_id($booking_ids); if($details) { $total_sqft+=$details->dimension; array_push($project_ids,$details->project_id); array_push($site_numbers,$details->site_number); array_push($executive_ids,$details->reference); } } if($total_sqft) { return $this->response->setJSON(['result'=>1,'message'=>$total_sqft,'project_id'=>$project_ids,'site_number'=>$site_numbers,'executive_id'=>$executive_ids]); } else { return $this->response->setJSON(['result'=>0,'message'=>'Not found']); } } public function add_logistic_incentive() { $gss_model=new Gss_model(); $db = \Config\Database::connect(); $table = 'gss_logistic_incentives'; $array = array(); $broker_id = $this->request->getpost('log_broker_id'); $project_id[] = $this->request->getpost('log_project_id'); $site_number[] = $this->request->getpost('log_site_number'); foreach ($project_id as $keys => $values) { $project_ids = $values; if(!empty($project_ids)) { $res['project_id']=$values; $res['site_number']=$site_number[$keys]; array_push($array,$res); $projects_sites= json_encode($array); } else { $projects_sites= ""; } } $total_sites = $this->request->getpost('total_sites'); $amount = $this->request->getpost('tot_amt'); $log_remark = $this->request->getpost('log_remark'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $data = array('broker_id'=>$broker_id, 'projects_sites'=>$projects_sites, 'total_sites'=>$total_sites, 'amount'=>$amount, 'log_remark'=>$log_remark, 'delete_status'=>'ACTIVE', 'created_at'=>$created_at ); $result = $gss_model->insert1($table,$data); $project_id = $this->request->getpost('log_project_id'); $site_numbers = $this->request->getpost('log_site_number'); $explode_project_ids= explode(",",$project_id); $explode_site_numbers= explode(",",$site_numbers); foreach($explode_project_ids as $key=>$vals) { $tble_sites='gss_new_sites'; $condition_sites=array('project_id'=>$vals,'site_number'=>$explode_site_numbers[$key]); $update_data=array('log_incentive_status'=>'YES'); $gss_model->update1($tble_sites,$condition_sites,$update_data); $tble_booking_details='gss_booking_details'; $condition_booking=array('project_id'=>$vals,'site_number'=>$explode_site_numbers[$key]); $update_booking_data=array('selected_incentive_status'=>'YES'); $gss_model->update1($tble_booking_details,$condition_booking,$update_booking_data); } if($result) { return $this->response->setJSON(['result'=>1,'message'=>"Added successfully"]); } else { return $this->response->setJSON(['result'=>0,'message'=>"Something went wrong.. try again"]); } } public function add_insentive_calculation() { $db = \Config\Database::connect(); $gss_model=new Gss_model(); $admin_id = session()->get('admin_id'); $reference = $this->request->getpost('calc_reference'); $booking_id = $this->request->getpost('calc_booking_id'); $table_reference ='gss_booking_details'; $where_reference = array('shared_between_executive'=>$reference,'booking_id'=>$booking_id); $get_reference = $gss_model->get_where_row($table_reference,$where_reference); if(empty($get_reference)) { $total_sqft = $this->request->getpost('calc_total_sqft'); $rate_per_sqft = $this->request->getpost('calc_rate_per_sqft'); $total_amount_fixed = $this->request->getpost('calc_total_amount_fixed'); $total_amount_fixed = str_replace(',', '', $total_amount_fixed); $incentive_on_agmnt = $this->request->getpost('calc_incentive_on_agmnt'); $incentive_on_agmnt = str_replace(',', '', $incentive_on_agmnt); $incentive_on_regn = $this->request->getpost('calc_incentive_on_regn'); $incentive_on_regn = str_replace(',', '', $incentive_on_regn); $insentive_perc = $this->request->getpost('calc_insentive_perc'); $balance = $this->request->getpost('calc_balance'); $balance = str_replace(',', '', $balance); $source = $this->request->getpost('calc_source'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $calc_table = 'gss_incentive_reports'; $calc_data = array( 'reference' => $reference, 'booking_id' => $booking_id, 'total_sqft' => $total_sqft, 'rate_per_sqft' => $rate_per_sqft, 'total_amount_fixed' => $total_amount_fixed, 'incentive_on_agmnt' => $incentive_on_agmnt, 'incentive_on_regn' => $incentive_on_regn, // 'insentive_perc' => $insentive_perc, 'balance' => $balance, 'source' => $source, 'created_by' => $admin_id, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ); if($insentive_perc == '40%') { $calc_data['insentive_perc'] = $insentive_perc; $table ='gss_booking_details'; $where_booking = array('booking_id'=>$booking_id); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if ($get_booking_row && $get_booking_row->sixty_status != "") { $calc_data['sixty_status'] = $get_booking_row->sixty_status; } else { $calc_data['sixty_status'] = ""; } $get_booking_row = $gss_model->get_where_row($table,$where_booking); if ($get_booking_row && $get_booking_row->both_status != "") { $calc_data['both_status'] = $get_booking_row->both_status; } else { $calc_data['both_status'] = ""; } } else if($insentive_perc == '60%') { $calc_data['insentive_perc_sixty'] = $insentive_perc; $table ='gss_booking_details'; $where_booking = array('booking_id'=>$booking_id); $get_booking_row = $gss_model->get_where_row($table, $where_booking); if ($get_booking_row && $get_booking_row->fourty_status != "") { $calc_data['fourty_status'] = $get_booking_row->fourty_status; } $get_booking_row = $gss_model->get_where_row($table,$where_booking); if ($get_booking_row && $get_booking_row->both_status != "") { $calc_data['both_status'] = $get_booking_row->both_status; } } else { $calc_data['insentive_perc_both'] = $insentive_perc; $table ='gss_booking_details'; $where_booking = array('booking_id'=>$booking_id); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if ($get_booking_row && $get_booking_row->fourty_status != "") { $calc_data['fourty_status'] = $get_booking_row->fourty_status; } else { $calc_data['fourty_status'] = ""; } if ($get_booking_row && $get_booking_row->sixty_status != "") { $calc_data['sixty_status'] = $get_booking_row->sixty_status; } else { $calc_data['sixty_status'] = ""; } } $where_booking = array('booking_id'=>$booking_id); $inc_data = $gss_model->get_where_row($calc_table,$where_booking); if(!empty($inc_data)) { $update_data = array('reference' => $reference, 'total_sqft' => $total_sqft, 'rate_per_sqft' => $rate_per_sqft, 'total_amount_fixed' => $total_amount_fixed, 'incentive_on_agmnt' => $incentive_on_agmnt, 'incentive_on_regn' => $incentive_on_regn, // 'insentive_perc' => $insentive_perc, 'balance' => $balance, 'source' => $source, 'updated_at' => $created_at, ); if($insentive_perc == '40%') { $update_data['insentive_perc'] = $insentive_perc; $table ='gss_booking_details'; $where_booking = array('booking_id'=>$booking_id); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if ($get_booking_row && $get_booking_row->sixty_status != "") { $update_data['sixty_status'] = $get_booking_row->sixty_status; } else { $update_data['sixty_status'] = ""; } $get_booking_row = $gss_model->get_where_row($table,$where_booking); if ($get_booking_row && $get_booking_row->both_status != "") { $update_data['both_status'] = $get_booking_row->both_status; } else { $update_data['both_status'] = ""; } } else if($insentive_perc == '60%') { $table ='gss_booking_details'; $where_booking = array('booking_id'=>$booking_id); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if ($get_booking_row && $get_booking_row->fourty_status != "") { $update_data['fourty_status'] = $get_booking_row->fourty_status; } else { $update_data['fourty_status'] = ""; } $get_booking_row = $gss_model->get_where_row($table, $where_booking); if ($get_booking_row && $get_booking_row->both_status != "") { $update_data['both_status'] = $get_booking_row->both_status; } else { $update_data['both_status'] = ""; } $update_data['insentive_perc_sixty'] = $insentive_perc; } else { $table ='gss_booking_details'; $where_booking = array('booking_id'=>$booking_id); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if ($get_booking_row && $get_booking_row->fourty_status != "") { $update_data['fourty_status'] = $get_booking_row->fourty_status; } else { $update_data['fourty_status'] = ""; } if ($get_booking_row && $get_booking_row->sixty_status != "") { $update_data['sixty_status'] = $get_booking_row->sixty_status; } else { $update_data['sixty_status'] = ""; } $update_data['insentive_perc_both'] = $insentive_perc; } $update_result = $gss_model->update1($calc_table,$where_booking,$update_data); 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"]); } } else { $result = $gss_model->insert1($calc_table,$calc_data); if($result) { return $this->response->setJSON(['result'=> 1,'message' => "Inserted Successfully"]); } else { return $this->response->setJSON(['result'=> 0,'message' => "Something went wrong.. try again"]); } } } else { $total_sqft = $this->request->getpost('calc_total_sqft'); $rate_per_sqft = $this->request->getpost('calc_rate_per_sqft'); $total_amount_fixed = $this->request->getpost('calc_total_amount_fixed'); $total_amount_fixed = str_replace(',', '', $total_amount_fixed); $incentive_on_agmnt = $this->request->getpost('calc_incentive_on_agmnt'); $incentive_on_agmnt = str_replace(',', '', $incentive_on_agmnt); $incentive_on_regn = $this->request->getpost('calc_incentive_on_regn'); $incentive_on_regn = str_replace(',', '', $incentive_on_regn); $insentive_perc = $this->request->getpost('calc_insentive_perc'); $balance = $this->request->getpost('calc_balance'); $balance = str_replace(',', '', $balance); $source = $this->request->getpost('calc_source'); $date = new \DateTime('now', new \DateTimeZone('Asia/Kolkata')); $created_at = $date->format('Y-m-d H:i:s'); $calc_table = 'gss_incentive_reports'; $calc_data = array( 'reference2' => $reference, 'booking_id2' => $booking_id, 'total_sqft2' => $total_sqft, 'rate_per_sqft2' => $rate_per_sqft, 'total_amount_fixed2' => $total_amount_fixed, 'incentive_on_agmnt2' => $incentive_on_agmnt, 'incentive_on_regn2' => $incentive_on_regn, // 'insentive_perc' => $insentive_perc, 'balance2' => $balance, 'source2' => $source, 'created_by' => $admin_id, 'delete_status' => 'ACTIVE', 'created_at' => $created_at, ); if($insentive_perc == '40%') { $calc_data['insentive_perc2'] = $insentive_perc; $table ='gss_booking_details'; $where_booking = array('booking_id'=>$booking_id); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if($get_booking_row->sixty_status2 != "") { $calc_data['sixty_status2'] = $get_booking_row->sixty_status2; } else { $calc_data['sixty_status2'] = ""; } $get_booking_row = $gss_model->get_where_row($table,$where_booking); if($get_booking_row->both_status2 != "") { $calc_data['both_status2'] = $get_booking_row->both_status2; } else { $calc_data['both_status2'] = ""; } } else if($insentive_perc == '60%') { $calc_data['insentive_perc_sixty2'] = $insentive_perc; $table ='gss_booking_details'; $where_booking = array('booking_id'=>$booking_id); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if($get_booking_row->fourty_status2 != "") { $calc_data['fourty_status2'] = $get_booking_row->fourty_status2; } $get_booking_row = $gss_model->get_where_row($table,$where_booking); if($get_booking_row->both_status2 != "") { $calc_data['both_status2'] = $get_booking_row->both_status2; } } else { $calc_data['insentive_perc_both2'] = $insentive_perc; $table ='gss_booking_details'; $where_booking = array('booking_id'=>$booking_id); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if($get_booking_row->fourty_status2 != "") { $calc_data['fourty_status2'] = $get_booking_row->fourty_status2; } else { $calc_data['fourty_status2'] = ""; } if($get_booking_row->sixty_status2 != "") { $calc_data['sixty_status2'] = $get_booking_row->sixty_status2; } else { $calc_data['sixty_status2'] = ""; } } $where_booking2 = array('booking_id2'=>$booking_id); $inc_data = $gss_model->get_where_row($calc_table,$where_booking2); if(!empty($inc_data)) { $update_data = array('reference2' => $reference, 'total_sqft2' => $total_sqft, 'rate_per_sqft2' => $rate_per_sqft, 'total_amount_fixed2' => $total_amount_fixed, 'incentive_on_agmnt2' => $incentive_on_agmnt, 'incentive_on_regn2' => $incentive_on_regn, 'balance2' => $balance, 'source2' => $source, 'updated_at' => $created_at, ); if($insentive_perc == '40%') { $update_data['insentive_perc2'] = $insentive_perc; $table ='gss_booking_details'; $where_booking = array('booking_id'=>$booking_id); $get_booking_row = $resultgss_model->get_where_row($table,$where_booking); if($get_booking_row->sixty_status2 != "") { $update_data['sixty_status2'] = $get_booking_row->sixty_status2; } else { $update_data['sixty_status2'] = ""; } $get_booking_row = $gss_model->get_where_row($table,$where_booking); if($get_booking_row->both_status2 != "") { $update_data['both_status2'] = $get_booking_row->both_status2; } else { $update_data['both_status2'] = ""; } } else if($insentive_perc == '60%') { $table ='gss_booking_details'; $where_booking = array('booking_id'=>$booking_id); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if($get_booking_row->fourty_status2 != "") { $update_data['fourty_status2'] = $get_booking_row->fourty_status2; } else { $update_data['fourty_status2'] = ""; } $get_booking_row = $gss_model->get_where_row($table,$where_booking); if($get_booking_row->both_status2 != "") { $update_data['both_status2'] = $get_booking_row->both_status2; } else { $update_data['both_status2'] = ""; } $update_data['insentive_perc_sixty2'] = $insentive_perc; } else { $table ='gss_booking_details'; $where_booking = array('booking_id'=>$booking_id); $get_booking_row = $gss_model->get_where_row($table,$where_booking); if($get_booking_row->fourty_status2 != "") { $update_data['fourty_status2'] = $get_booking_row->fourty_status2; } else { $update_data['fourty_status2'] = ""; } if($get_booking_row->sixty_status2 != "") { $update_data['sixty_status2'] = $get_booking_row->sixty_status2; } else { $update_data['sixty_status2'] = ""; } $update_data['insentive_perc_both2'] = $insentive_perc; } $update_result = $gss_model->update1($where_booking2,$calc_table,$update_data); 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"]); } } else { $result = $gss_model->insert1($calc_table,$calc_data); if($result) { return $this->response->setJSON(['result'=> 1,'message' => "Inserted Successfully"]); } else { return $this->response->setJSON(['result'=> 0,'message' => "Something went wrong.. try again"]); } } } } public function pending_executive_incentive() { $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'); } $executive = $_GET['reference']; $result = $gss_model->get_pending_executive_incentives($from_date,$to_date,$executive); if($result) { echo json_encode($result); } else { echo json_encode(array('result'=>0)); } } public function get_table_details_invoice() { $ids = []; // Check if it's an AJAX request if ($this->request->isAJAX()) { $contentType = $this->request->getHeaderLine('Content-Type'); // Check if request sent JSON (used by export) if (str_contains($contentType, 'application/json')) { $json = $this->request->getJSON(true); $ids = $json['id'] ?? []; } else { // Used by print (form-urlencoded) $ids = $this->request->getPost('id') ?? []; } } // Validate IDs if (!is_array($ids) || empty($ids)) { return $this->response->setJSON(['result' => 0, 'message' => 'Invalid or missing ID list']); } // DB Query $db = \Config\Database::connect(); $builder = $db->table('gss_invoice_details A'); $builder->select('A.*, B.project_name'); $builder->join('gss_new_projects B', 'B.project_id = A.project_id'); $builder->whereIn('A.id', $ids); $query = $builder->get(); $results = $query->getResult(); // Format result $data = []; foreach ($results as $row) { $created = new \DateTime($row->created_at); $data[] = [ 'id' => $row->id, 'project_name' => $row->project_name, 'site_ids' => $row->site_ids, 'site_numbers' => $row->site_numbers, 'invoice_no' => $row->invoice_no, 'invoice_number' => $row->invoice_number, 'invoice_type' => $row->invoice_type, 'invoice_to' => $row->invoice_to, 'total_sqft' => $row->total_sqft, 'rate_per_sqft' => $row->rate_per_sqft, 'without_gst_total_amt' => $row->without_gst_total_amt, 'sgst' => $row->sgst, 'cgst' => $row->cgst, 'total_cgst' => $row->total_cgst, 'total_sgst' => $row->total_sgst, 'with_gst_total_amt' => $row->with_gst_total_amt, 'bank_name' => $row->bank_name, 'created_at' => $created->format('Y-m-d') ]; } return $this->response->setJSON($data); } public function invoice_print() { $admin_id = session()->get('admin_id'); if($admin_id) { $gss_model=new Gss_model(); $id=$_GET['id']; $table ='gss_bank_details'; $where = array('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 subcommission_payment() { $table = 'gss_sub_commission_payments'; $mgnt_table = 'gss_management'; $request = service('request'); $booking_id = $request->getPost('management_id'); $gss_model = new \App\Models\Gss_model(); // adjust if using a different namespace $order_by = 'sub_payment_id'; $where_booking = ['booking_id' => $booking_id, 'delete_status' => 'ACTIVE']; $id_result = $gss_model->get_where_row($mgnt_table, $where_booking); if ($id_result) { $management_id = $id_result->management_id; $where = ['management_id' => $management_id, 'delete_status' => 'ACTIVE']; $result = $gss_model->get_where_row_orderby($table, $where, $order_by); if ($result) { return $this->response->setJSON([ 'result' => 1, 'commission_payment' => $result ]); } } return $this->response->setJSON([ 'result' => 0, 'message' => 'No data available' ]); } public function get_edit_executives() { $gss_model=new Gss_model(); $broker_id = $this->request->getpost('broker_id'); $broker_table = 'gss_brokers'; $associate_order_by = 'associate_name'; $where_logistics = array('delete_status'=>'ACTIVE','type'=>'Executives'); $db = \Config\Database::connect(); $builder = $db->table($broker_table); $result = $builder ->select('*') ->where($where_logistics) ->orderBy($associate_order_by, 'ASC') ->get() ->getResult(); $booking_id = $this->request->getpost('booking_id'); $where = array('booking_id'=>$booking_id); $table = "gss_booking_details"; $result2 = $gss_model->get_where_row($table,$where); if($result) { return $this->response->setJSON(['result'=>1,'executives'=>$result,'message'=>$result2]); } else { return $this->response->setJSON(['result'=>0]); } } public function update_shared_executive_between() { $db = \Config\Database::connect(); $gss_model=new Gss_model(); $booking_id = $this->request->getpost('edit_exe_booking_id'); $shared_between_exe = $this->request->getpost('edit_shared_to_executive_ids'); $shared_to_exe = $this->request->getpost('edit_shared_exe_to'); $shared_exe_amount = $this->request->getpost('edit_shared_exe_amount'); $shared_amount = $this->request->getpost('edit_shared_total_amount'); $shared_percentage = $this->request->getpost('edit_shared_exe_percent'); $table = "gss_booking_details"; $where = array('booking_id'=>$booking_id); $data = array('shared_from_executive'=>$shared_to_exe,'shared_between_executive'=>$shared_between_exe,'shared_executive_amount'=>$shared_exe_amount,'shared_executive_percentage'=>$shared_percentage,'shared_amount'=>$shared_amount); $result = $gss_model->update1($table,$where,$data); if ($db->affectedRows() > 0) { return $this->response->setJSON(['result'=>1,'message'=>'Added!']); } else { return $this->response->setJSON(['result'=>0,'message'=>"No Data Changes to Update"]); } } }?>