mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-10-28 19:18:58 -04:00
build/refactor/fix: tighten tooling, rename accessors to camelCase, and correct model bugs * build: tighten gitignore, lockfile, and script config - gitignore /build and /.php-cs-fixer.cache - allow core-js@3.50.0 postinstall script in package.json * refactor: rename snake_case data accessors to camelCase Rename get_info, get_multiple_info, get_sale_items, get_sale_payments, and save_customer across Customer, Employee, Item, Sale, and Supplier models to PSR-12 camelCase, updating every call site in controllers, libraries, and views. * test: update calls to match renamed camelCase accessors Update HomeTest, ItemsControllerTest, and ItemTest to call getInfo()/getMultipleInfo() instead of the old snake_case model methods. * fix: correct independent bugs in Item, Item_taxes, and Attribute models - Item::delete()/delete_list(): let $this->db->transStatus() alone decide success instead of accumulating a bitwise-AND over intermediate results, which could report failure (and trigger error toasts) even when the delete had actually completed - Item_taxes: correct $table property from 'item_taxes' to 'items_taxes' - Attribute::getDefinitionNames(): pass an array to QueryBuilder->whereNotIn(), which requires one Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
92 lines
2.5 KiB
PHP
92 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Libraries\Sms_lib;
|
|
|
|
use App\Models\Person;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
|
|
class Messages extends Secure_Controller
|
|
{
|
|
private Sms_lib $sms_lib;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct('messages');
|
|
|
|
$this->sms_lib = new Sms_lib();
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getIndex(): string
|
|
{
|
|
return view('messages/sms');
|
|
}
|
|
|
|
/**
|
|
* @param int $person_id
|
|
* @return string
|
|
*/
|
|
public function getView(int $person_id = NEW_ENTRY): string
|
|
{
|
|
$person = model(Person::class);
|
|
$info = $person->getInfo($person_id);
|
|
|
|
foreach (get_object_vars($info) as $property => $value) {
|
|
$info->$property = $value;
|
|
}
|
|
$data['person_info'] = $info;
|
|
|
|
return view('messages/form_sms', $data);
|
|
}
|
|
|
|
/**
|
|
* @return ResponseInterface
|
|
*/
|
|
public function send(): ResponseInterface
|
|
{
|
|
$phone = $this->request->getPost('phone', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
|
$message = $this->request->getPost('message', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
|
|
|
$response = $this->sms_lib->sendSMS($phone, $message);
|
|
|
|
if ($response) {
|
|
return $this->response->setJSON(['success' => true, 'message' => lang('Messages.successfully_sent') . ' ' . esc($phone)]);
|
|
} else {
|
|
return $this->response->setJSON(['success' => false, 'message' => lang('Messages.unsuccessfully_sent') . ' ' . esc($phone)]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sends an SMS message to a user. Used in app/Views/messages/form_sms.php.
|
|
*
|
|
* @param int $person_id
|
|
* @return ResponseInterface
|
|
* @noinspection PhpUnused
|
|
*/
|
|
public function send_form(int $person_id = NEW_ENTRY): ResponseInterface
|
|
{
|
|
$phone = $this->request->getPost('phone', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
|
$message = $this->request->getPost('message', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
|
|
|
$response = $this->sms_lib->sendSMS($phone, $message);
|
|
|
|
if ($response) {
|
|
return $this->response->setJSON([
|
|
'success' => true,
|
|
'message' => lang('Messages.successfully_sent') . ' ' . esc($phone),
|
|
'person_id' => $person_id
|
|
]);
|
|
} else {
|
|
return $this->response->setJSON([
|
|
'success' => false,
|
|
'message' => lang('Messages.unsuccessfully_sent') . ' ' . esc($phone),
|
|
'person_id' => NEW_ENTRY
|
|
]);
|
|
}
|
|
}
|
|
}
|