Codeigniter select by supplierid - codeigniter

I am trying to select products by supplierid but code seems to return every product from database, I cant figure it out why but it must be something I am missing as I am not an expert in codeigniter, ireally apretiate your input on this, thx
-----Controller page-----
{
$this->data['store_products'] = $this->productss->get_products_by_supplier_id();
$this->data['store_suppliers'] = $this->productss->get_join_suppliers();
$this->data['tax_settings'] = $this->productss->get_all_taxs();
$this->data['store_taxs'] = $this->productss->get_join_taxs();
          
$this->load->view('products/by_supplier', $this->data);
}
----------- Model page-----
public function get_products_by_supplier_id()
    {
        $this->db->select('*');
$this->db->from('store_products');
$this->db->join('store_suppliers', 'store_products.supplierid = store_suppliers.supplierid','left');
$this->db->join('tax_settings', 'store_products.taxid = tax_settings.taxid','left');
$this->db->where('store_suppliers.supplierid',$supplierid);
       
       
            $query =  $this->db->get();
if ($query->num_rows() > 0)
{
return $query->result_array();
}
else
{
return array();
}
    }

Do you try to remove the parameter 'left' in the join query?

change this lines. the order of the comparison is important. I change it and run the query.
$this->db->join('store_suppliers', ' store_suppliers.supplierid = store_products.supplierid');
$this->db->join('tax_settings', 'tax_settings.taxid =store_products.taxid');

from where u will get the $supplierid
$this->db->where('store_suppliers.supplierid',$supplierid);
pass supplier id here
get_products_by_supplier_id() to
get_products_by_supplier_id($supplierid)

Sorted, url on index page wasn't properly passing the parameter.
was using -
removing base 64 encode solve the problem

Related

cursors - %notfound is false even when row is not returned

I have a cursor that is used to get some information about all the groups of a certain class some other processing.
It is possible that the query backing the cursor may not return any rows,
because there are no groups or the class id doesn't exist.
In these cases, I want to raise an exception.
The problem is that even though I insert a class id that doesn't exist the function goes straight to the 'else' .
Does enyone have an idea why?
Here's what it looks like:
create or replace function ReturnGroupsOfClass(class_id_in in integer) return sys_refcursor
is
      FunctionResult sys_refcursor;
     
      exception_no_class_found exception;
      pragma
      exception_init(exception_no_class_found,-2001);
begin    
      --a cursor of the group for class 'class_id_in'
      open FunctionResult for  
      select class_ID, group_day, group_startHour, count(*) as num_of_participants
      from Participant_In_Group
      where  class_id=class_id_in
      group by class_ID, group_day, group_startHour
      order by class_ID;
   
      if(FunctionResult%notfound)
            then
              raise exception_no_class_found;
       
      else
            dbms_output.put_line('you can view the cersor in the test window');
           
      end if;
      return(FunctionResult);
end ReturnGroupsOfClass;
  
The %notfound cursor attribute is only set following a fetch from the cursor. As your function only opens the FunctionResult cursor, its found/notfound status remains undefined.
If you fetch a row before the check (for testing purposes only, as the cursor is no use to the caller if you do this), then you get your ORA-02001 exception:
create or replace function returngroupsofclass
( class_id_in in integer )
return sys_refcursor
as
functionresult sys_refcursor;
exception_no_class_found exception;
pragma exception_init(exception_no_class_found, -2001);
begin
-- dummy cursor for testing:
open functionresult for
select dummy from dual where 1=2;
declare
testval dual.dummy%type;
begin
fetch functionresult into testval;
end;
if functionresult%notfound then
raise exception_no_class_found;
else
dbms_output.put_line('you can view the cursor in the test window');
end if;
return functionresult;
end returngroupsofclass;
Testing in PL/SQL Developer:
begin
:result := returngroupsofclass(class_id_in => :class_id_in);
end;
gives
ORA-02001: user SYS is not permitted to create indexes with freelist groups
ORA-06512: at "WILLIAM.RETURNGROUPSOFCLASS", line 23
ORA-06512: at line 2
I'm guessing 2001 might not be the error code you intended to link to this.

Laravel : Generate PDF file using Dompdf

i am submitting a search form and based on the posted values results are fetched from DB and shown on the result page. I want to download these results in a PDF file. I configured Dompdf and its downloading PDF with some test data as below :
public function Genderate_PDF()
{
$data = ['title' => 'some title'];
$pdf = PDF::loadView('pdf', $data);
return $pdf->download('mypdf.pdf');
}
but in my scenario instead of loading the pdf view I have to show results in a page and then export that page results to PDF on a button click( Export PDF). Can someone please guide me how can i achieve that
EDIT::
Below is the search result posted to view that i need to export as PDF
public function search(Request $request){
$result = \DB::table('matromonial_data');
if ($request->has('gender')) {
$result->where('gender', $request->input('gender'));
}
if ($request->has('age_from') && $request->has('age_to')) {
$datefrom=$request->input('age_from');
$dateto=$request->input('age_to');
$result->where(function($query) use ($datefrom,$dateto){
$query->whereBetween('age',array($datefrom,$dateto)) ;
});
}
if ($request->has('height_from') && $request->has('height_to')) {
$height_from=$request->input('height_from');
$height_to=$request->input('height_to');
$result->where(function($query) use ($height_from,$height_to){
$query->whereBetween('height',array($height_from,$height_to)) ;
});
}
if ($request->has('religion')) {
$result->whereIn('religion', $request->input('religion'));
}
if ($request->has('cast')) {
$result->whereIn('cast', $request->input('cast'));
}
if ($request->has('mother_tongue')) {
$result->whereIn('mother_tongue', $request->input('mother_tongue'));
}
if ($request->has('maritial_status')) {
$result->whereIn('maritial_status', $request->input('maritial_status'));
}
if ($request->has('country')) {
$result->whereIn('country', $request->input('country'));
}
if ($request->has('city')) {
$result->whereIn('city', $request->input('city'));
}
if ($request->has('profession')) {
$result->whereIn('profession', $request->input('profession'));
}
if ($request->has('education')) {
$result->whereIn('education', $request->input('education'));
}
if ($request->has('income')) {
$result->whereIn('income', $request->input('income'));
}
if ($request->has('keywords')) {
$result->where('keywords', 'like','%' . $request->input('keywords') .'%');
}
if ($request->has('smoking_status')) {
$result->where('smoking_status', $request->input('smoking_status'));
}
if ($request->has('drinking_status')) {
$result->where('drinking_status', $request->input('drinking_status'));
}
$data['result_set']=$result->get();
return view('admin/search_result', $data);
}

Laravel - How to combine multiple queries as one Eloquent Query

In my Laravel-5.8, I have these four queries accessng the same model:
$allLeaves = HrLeaveRequest::where('company_id', $userCompany)->whereYear('created_at', date('Y'))->count();
$pendingLeaves = HrLeaveRequest::where('leave_status', 1)->where('company_id', $userCompany)->whereYear('created_at', date('Y'))->count();
$rejectedLeaves = HrLeaveRequest::where('leave_status', 3)->where('company_id', $userCompany)->whereYear('created_at', date('Y'))->count();
$approvedLeaves = HrLeaveRequest::where('leave_status', 4)->where('company_id', $userCompany)->whereYear('created_at', date('Y'))->count();
How do I combine the four queries as one
something similar to this
$gender_unpublished_record = HrEmployee::selectRaw('count(gender_code) as count,gender_code, if (gender_code = 1, "Male", "Female") as gender')->whereNotIn('employee_code', $publishedgoals)->where('company_id', $userCompany)->where('hr_status', 0)->groupBy('gender_code')->get();
The one above only have 0 or 1. But what I want to achive takes care of everything in the table, leave_status as 1, 3 and 4
Thank you
in your Company Model you should have the relation:
public function HrLeaveRequests()
{
return $this->hasMany(HrLeaveRequest::class,'company_id');
}
now you could use withCount:
$value=Company::where('company_id',$userCompany)->withCount(['HrLeaveRequests as allLeaves'=>function($query){
$query ->whereYear('created_at', date('Y'));
},
'HrLeaveRequests as pendingLeaves'=>function($query){
$query->where('leave_status', 1)->whereYear('created_at', date('Y'));
},
'HrLeaveRequests as rejectedLeaves'=>function($query){
$query->where('leave_status', 3)->whereYear('created_at', date('Y'));
},
'HrLeaveRequests as approvedLeaves'=>function($query){
$query->where('leave_status', 4)->whereYear('created_at', date('Y'));
},
])->get();

when i want change get become post it not work well

i have problem when i want to change Get become Post.
when i use Get i can get the data
but when use post i cannot get the data please help me
i have change the web.php or routes become Post but i cannot get my data when i use post
i have change get become post in my web.php in my laravel. but the result not the same
this is my code in laravel
public function getHistoryEvent(Request $request) {
$consumer_data = array();
$consumer_data['consumer_key'] = request()->header('consumer-key');
$consumer_data['consumer_secret'] = request()->header('consumer-secret');
$consumer_data['consumer_nonce'] = request()->header('consumer-nonce');
$consumer_data['consumer_device_id'] = request()->header('consumer-device-id');
$consumer_data['consumer_url'] = __FUNCTION__;
$authController = new AppSettingController();
$authenticate = $authController->apiAuthenticate($consumer_data);
if($authenticate==1 || $authenticate==0){
$event = DB::table('u_history_events')
->select('u_history_events.history_events_id','u_history_events.events_image','u_history_events.events_description','u_history_events.date_create')
->where('u_history_events.events_id',$request->events_id)
->where('u_history_events.kode_customers',$request->kode_customer)
->get();
$responseData = array('success'=>'1', 'data'=>$event, 'message'=>"Success.");
}else{
$responseData = array('success'=>'0', 'data'=>array(), 'message'=>"Unauthenticated call.");
}
$orderResponse = json_encode($responseData);
print $orderResponse;
}
when use get i can get this data the result are :
{"success": "1",
"data": [
{"history_events_id": 2,
"events_image": "",
"events_description": "",
"date_create": "2019-05-11 10:59:01"
},
{
"history_events_id": 3,
"events_image": "",
"events_description": "",
"date_create": "2019-05-11 11:59:35"
}
}
but when i use post i only get
{"success":"1","data":[],"message":"Success."}
I am no Laravel expert, but according to the docs, looks like you have to explicitly define a route for the POST verb to your controller's method:
Route::post($uri, $callback);
Or according to Controllers docs:
// change <your path here> and <your method name> to your desired path and
// method names
Route::get('<your path here>', 'AppSettingController#<your method name>');
I also recommend you to read MDN's An overview of HTTP.

ASP.NET Core, Web API RouteAttribute with query string as template

I need to make a ASP.NET Core, Web API that supports multiple HttpGet verbs with the only difference being a query string, but it seems that query strings cannot be part of the route template -- is that true?
The route templates are very similar, in fact they only differ by query string.
[Authorize]
public class SymbolsController : Controller
{
   [
HttpGet,
Route("api/symbols")
]
   public Task<IEnumerable<Symbol>> Symbols([FromServices] ISymbolService symbolService)
   {
       return symbolService.GetSymbolsAsync();
   }
   [
HttpGet,
Route("api/symbols?{childrenOf=id}")
]
   public Task<IEnumerable<Symbol>> ValidChildren(
[FromQuery] Guid id,
       [FromServices] ISymbolService symbolService)
   {
       return symbolService.GetValidChildrenAsync(id);
   }
}
This throws an exception as the ? is not a valid character in the route template. How can I achieve this?
I figured out an easier and more straightforward solution. I am simply using the FromQuery attribute and leaving the template simple. I check for the presence of the id variable and handle it accordingly.
[HttpGet, Route("api/symbols")]
public Task<IEnumerable<Symbol>> Symbols(
[FromQuery] Guid id,
[FromServices] ISymbolService symbolService) =>
id == default
? symbolService.GetSymbolsAsync()
: symbolService.GetValidChildrenAsync(id);
//eg GET api/symbols
//eg GET api/symbols?childrenOf={someGuid}
[HttpGet("api/symbols")]
public Task<IEnumerable<Symbol>> Symbols(
[FromServices] ISymbolService symbolService,
Guid? childrenOf = null)
{
if (childredOf.HasValue) {
return ValidChildren(childredOf.Value, symbolService);
}
return symbolService.GetSymbolsAsync();
}
Task<IEnumerable<Symbol>> ValidChildren(
Guid id,
ISymbolService symbolService)
{
return symbolService.GetValidChildrenAsync(id);
}

Resources