diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index 0e3b7c4..c9d54f0 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -610,14 +610,13 @@ class Customer extends BaseController public function import_donor() { - - $ip_address = $_SERVER['REMOTE_ADDR']; + $ip_address = $_SERVER['REMOTE_ADDR']; helper('session'); $session_uid = get_logged_user_id(); $session_bid = get_business_id(); - $json = []; // Arr - Json For Message FrontEnd + $response = []; // Arr - response For Message FrontEnd $list = []; // Arr - Store on DB $path = ROOTPATH . 'public/import/donor/'; $fileNewName = ""; @@ -627,7 +626,6 @@ class Customer extends BaseController if (!is_dir($path)) { mkdir($path, 0777, true); } - $fileName = $file->getName(); if ($fileName !== "") { if ($file->isValid() && !$file->hasMoved()) { @@ -636,10 +634,9 @@ class Customer extends BaseController $fileNewName = $newName; } } - if (!$fileNewName) { - $json = ['error_message' => "Failed to upload file"]; - return $this->response->setJSON($json); + $response = ['error_message' => "Failed to upload file"]; + return $this->response->setJSON($response); } $arr_file = explode('.', $fileName); @@ -649,59 +646,100 @@ class Customer extends BaseController } else if ('xlsx' == $extension) { $reader = new ReaderXlsx(); } else { - $json = ['error_message' => "Unsupported file type"]; - return $this->response->setJSON($json); + $response = ['error_message' => "Unsupported file type"]; + return $this->response->setJSON($response); } if (!$reader) { - $json = ['error_message' => "Failed to initialize reader"]; - return $this->response->setJSON($json); + $response = ['error_message' => "Failed to initialize reader"]; + return $this->response->setJSON($response); } $spreadsheet = $reader->load($path.$fileNewName); - $sheet_data = $spreadsheet->getActiveSheet()->toArray(); - - if(!empty($sheet_data)){ - foreach ($sheet_data as $key => $val) { - if ($key != 0) { // key zero - header - $list[] = [ - 'business_id' => $session_bid, - 'first_name' => $val[0], - 'donor_type' => $val[1], - 'org_name' => $val[2] ? $val[2] : null , - 'org_reg_details' => $val[3] ? $val[3] : null, - 'mobile_no' => $val[4] ? $val[4] : null, - 'email' => $val[5], - 'pan_no' => $val[6], - 'adhar_no' => $val[7], - 'passport_no' => $val[8] ? $val[8] : null , - 'address' => $val[9], - 'country' => $val[10], - 'state' => $val[11], - 'city' => $val[12], - 'postal_code' => $val[13], - 'created_by' => $session_uid, - 'XL_file_name' => $fileNewName, - 'ip_address' => $ip_address - ]; + $sheet_data = $spreadsheet->getActiveSheet()->toArray(); + if (!empty($sheet_data)) { + $flag = 0; + $final_notes = []; + $list = []; + foreach ($sheet_data as $key => $val) { + + if ($key != 0 && trim($val[0]) && trim($val[1])) { // key zero - header + $flag = 0; + $notes = []; + if ($val[4]) { + $validate = $this->check_existing($val[4], 'donor', 'mobile_no'); + if ($validate) { $notes[] = $validate; $flag++;} + } + if ($val[5]) { + $validate = $this->check_existing($val[5], 'donor', 'email'); + if ($validate) { $notes[] = $validate; $flag++;} + } + if ($val[6]) { + $validate = $this->check_existing($val[6], 'donor', 'pan_no'); + if ($validate) { $notes[] = $validate; $flag++;} + } + if ($val[7]) { + $validate = $this->check_existing($val[7], 'donor', 'adhar_no'); + if ($validate) { $notes[] = $validate; $flag++;} + } + if ($val[8]) { + $validate = $this->check_existing($val[8], 'donor', 'passport_no'); + if ($validate) { $notes[] = $validate; $flag++;} + } + if ($flag > 0) { + $final_notes[] = $val[0] . ' has duplicate entries: ' . implode(',', $notes); + } else { + $list[] = [ + 'business_id' => $session_bid, + 'first_name' => $val[0], + 'donor_type' => ucfirst(strtolower($val[1])), + 'org_name' => $val[2] ? $val[2] : null, + 'org_reg_details' => $val[3] ? $val[3] : null, + 'mobile_no' => $val[4] ? $val[4] : null, + 'email' => $val[5], + 'pan_no' => $val[6], + 'adhar_no' => $val[7] ? $val[7] : null, + 'passport_no' => $val[8] ? $val[8] : null, + 'address' => $val[9] ? $val[9] : null, + 'country' => $val[10] ? $val[10] : null, + 'state' => $val[11] ? $val[11] : null, + 'city' => $val[12] ? $val[12] : null, + 'postal_code' => $val[13] ? $val[13] : null, + 'created_by' => $session_uid, + 'XL_file_name' => $fileNewName, + 'ip_address' => $ip_address + ]; + } + } } + + + if (count($list) > 0) { + $CustomerModel = new CustomerModel(); + $result = $CustomerModel->bulkInsert($list); + $response = $result ? [ + 'success_message' => count($list) . " Contributors imported successfully. " . implode("\n", $final_notes) + ] : ['error_message' => "Something went wrong. Please try again."]; + } else { + $response = ['error_message' => "No new record is found." . implode("\n", $final_notes)]; + } + } else { + $response = ['error_message' => "There is no record to import"]; } - }else{ - $json = ['error_message' => "There is no record to import"]; - return $this->response->setJSON($json); + return $this->response->setJSON($response); } - - if (count($list) > 0) { - $CustomerModel = new CustomerModel(); - - $result = $CustomerModel->bulkInsert($list); - ($result) ? ['success_message' => "All Entries are imported successfully."] - : ['error_message' => "Something went wrong. Please try again."]; - } else { - $json = ['error_message' => "No new record is found."]; + + public function check_existing($value, $table, $field) { + $model = new CustomerModel(); + $model->setTable($table); + $where = [$field => $value]; + $check_existing = $model->where($where)->findAll(); + + $statement_string = ucfirst(str_replace('_', ' ', $field)); + $notes = ''; + if (!empty($check_existing)) { + $notes = $statement_string . " already exists"; + } + return $notes; } - return $this->response->setJSON($json); - } - - } diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index d823e3c..9f6ce6a 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -19,6 +19,9 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use PhpOffice\PhpSpreadsheet\Reader\Csv as ReaderCsv; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as ReaderXlsx; +use PhpOffice\PhpSpreadsheet\Cell\DataType; +use PhpOffice\PhpSpreadsheet\Style\NumberFormat; + class Invoice extends BaseController { @@ -148,6 +151,7 @@ class Invoice extends BaseController $data['causes'] = $bmodel->select('*')->where('business_id', (int)get_business_id())->where('isactive',1)->get()->getResult(); $data['campaign'] = $model->getData('campaign', $where); + $data['invoice_number_formatting'] = $model->getData('business', $where); $data['receipt_type'] = "individual"; if ($id === '0') { @@ -798,13 +802,18 @@ class Invoice extends BaseController $sheet->getStyle($cell)->getFont()->setSize($cell == 'B3' ? 14 : 12); $sheet->getStyle($cell)->getFont()->setBold(true); } - if($export){ $row = 6; // Start from row 6 foreach ($export as $d) { $col = 'A'; // Start from column A foreach ($d as $value) { + if (is_numeric($value)) { + $sheet->setCellValueExplicit($col . $row, $value, DataType::TYPE_STRING); + $sheet->getStyle($col . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER); + } else { + $sheet->setCellValue($col . $row, $value); + } $sheet->setCellValue($col . $row, $value); $col++; } diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php index 407790c..00d8a14 100755 --- a/app/Controllers/Notifications.php +++ b/app/Controllers/Notifications.php @@ -195,9 +195,10 @@ class Notifications extends BaseController public function template_creation() { + $session_bid = get_business_id(); $data['page_name'] = 'Template Details'; $model = new NotificationModel(); - $data['template'] = $model->getTemplateDetails(); + $data['template'] = $model->getTemplateDetails($session_bid); $this->render_page('template_creation', $data); // echo "templates";die; } @@ -330,10 +331,10 @@ class Notifications extends BaseController //Campaign Creation public function campaign_creation() - { + { $session_bid = get_business_id(); $data['page_name'] = 'Campaign Details'; $model = new NotificationModel(); - $data['campaign'] = $model->getCampaignDetails(); + $data['campaign'] = $model->getCampaignDetails($session_bid); $this->render_page('campaign_creation', $data); // echo "templates";die; } diff --git a/app/Models/NotificationModel.php b/app/Models/NotificationModel.php index 73c3d04..65a63b2 100644 --- a/app/Models/NotificationModel.php +++ b/app/Models/NotificationModel.php @@ -41,12 +41,13 @@ class NotificationModel extends Model ->get()->getResultArray(); } - public function getTemplateDetails(){ + public function getTemplateDetails($session_bid){ return $this->db->table('templates as T' ) ->join('users as U1', 'U1.user_id = T.created_by', 'left') ->join('users as U2', 'U2.user_id = T.updated_by', 'left') ->select('T.template_id,T.template_name,T.mode,T.created_on,T.created_by,T.updated_on,T.updated_by,DATE_FORMAT(T.created_on, "%d/%m/%Y %h:%i %p") AS formatted_created_on,concat(U1.first_name," ",U1.last_name) as created_by_name,concat(U2.first_name," ",U2.last_name) as updated_by_name,T.isactive') ->whereNotIn('T.template_name',array('EXPIRAY_NOTIFY_TEMPLATE_EMAIL','EXPIRAY_NOTIFY_TEMPLATE_WHATSAPP')) + ->where('U1.business_id =',$session_bid) ->get()->getResultArray(); } @@ -82,13 +83,14 @@ class NotificationModel extends Model return $statement; } -public function getCampaignDetails(){ +public function getCampaignDetails($session_bid){ $result = $this->db->table('notification_campaign as NC' ) ->join('users as U1', 'U1.user_id = NC.created_by', 'left') ->join('users as U2', 'U2.user_id = NC.updated_by', 'left') ->join('templates as T', 'T.template_id = NC.template_id', 'left') ->select('NC.campaign_id,NC.campaign_name,T.template_id,T.template_name,NC.mode,NC.created_on,NC.created_by,NC.updated_on,NC.updated_by,DATE_FORMAT(NC.created_on, "%d/%m/%Y %h:%i %p") AS formatted_created_on,concat(U1.first_name," ",U1.last_name) as created_by_name,concat(U2.first_name," ",U2.last_name) as updated_by_name,NC.isactive,NC.group_id,NC.scheduled_date,if(NC.scheduled_time IS NULL ,"",NC.scheduled_time) as scheduled_time') ->whereNotIn('T.template_name',array('EXPIRAY_NOTIFY_TEMPLATE_EMAIL','EXPIRAY_NOTIFY_TEMPLATE_WHATSAPP')) + ->where('U1.business_id =',$session_bid) ->get()->getResultArray(); if (!empty($result)) { diff --git a/app/Views/audit_history.php b/app/Views/audit_history.php index 7c969ce..d9cfdbd 100644 --- a/app/Views/audit_history.php +++ b/app/Views/audit_history.php @@ -15,8 +15,8 @@ Action Module Key - Old Value New Value + Old Value Updated By Updated On diff --git a/app/Views/business_form.php b/app/Views/business_form.php index d96d89d..1dbc4d4 100644 --- a/app/Views/business_form.php +++ b/app/Views/business_form.php @@ -80,7 +80,7 @@ - +
@@ -160,11 +160,12 @@
- Auto-Text Copied from Buiness title field (First time only) + Auto-text copied from Organization Name field (First time only. If you want to change it means please edit.)
+ Auto-text copied from Organization Name field (First time only. If you want to change it means please edit.)
@@ -241,24 +242,24 @@
- +
Please provide.
- +
Please provide.
- +
Please provide.
- +
Please provide.
@@ -556,20 +557,32 @@ \ No newline at end of file diff --git a/public/import/sample.xlsx b/public/import/sample.xlsx deleted file mode 100644 index 3ff064a..0000000 Binary files a/public/import/sample.xlsx and /dev/null differ diff --git a/public/import/sample_contributor.xlsx b/public/import/sample_contributor.xlsx index 3ff064a..4dcb27c 100644 Binary files a/public/import/sample_contributor.xlsx and b/public/import/sample_contributor.xlsx differ