diff --git a/ci4/app/Controllers/Test.php b/ci4/app/Controllers/Test.php index 9ee22475..b96eb56c 100755 --- a/ci4/app/Controllers/Test.php +++ b/ci4/app/Controllers/Test.php @@ -31,7 +31,8 @@ class Test extends BaseController public function index() { - $this->sendMail('prueba', 'Esto es una prueba', ['jaimejimenezortega@gmail.com','jaime0jimenez0ortega@gmail.com']); + $modelCliente = model('App\Models\Clientes\ClienteModel'); + var_dump($modelCliente->getPendienteCobro(1284)); } private function sendMail($subject, $body, $recipient) diff --git a/ci4/app/Models/Clientes/ClienteModel.php b/ci4/app/Models/Clientes/ClienteModel.php index 79af78df..29bcf168 100755 --- a/ci4/app/Models/Clientes/ClienteModel.php +++ b/ci4/app/Models/Clientes/ClienteModel.php @@ -402,4 +402,36 @@ class ClienteModel extends \App\Models\BaseModel ->groupEnd()->get()->getResultObject(); } + + public function getPendienteCobro($cliente_id = -1){ + + $pendiente_old = $this->getTotalPendienteOldERP($cliente_id); + $db = \Config\Database::connect('default'); // Conectar a olderp + $builder = $db->table('vista_importe_pendiente_cliente t1') + ->select('*') + ->where('t1.cliente_id', $cliente_id); + $query = $builder->get(); + $valor = $query->getRow(); + if($valor){ + return [floatval($valor->total_pendiente) , floatval($pendiente_old)]; + }else{ + return [0 , floatval($pendiente_old)]; + } + + } + + private function getTotalPendienteOldERP($customer_id = -1){ + + $db = \Config\Database::connect('old_erp'); // Conectar a olderp + $builder = $db->table('vista_importe_pendiente_cliente t1') + ->select('*') + ->where('t1.customer_id', $customer_id); + $query = $builder->get(); + $valor = $query->getRow(); + if($valor){ + return $valor->total_pendiente; + }else{ + return 0; + } + } }