I am new to Grocery CRUD.
I am impressed by how much time saver this library is and i want to thank all great developers who worked on this project.
i have a small problem with showing the date field in the table. when i press the edit button , it's shown in the edit and view pages.
but it doesn't appear in the table.
Even if i create the record myself from the add record button, it's saved successfully but not shown in the table.
i have checked many things like the default format of the date in the library.
$config['grocery_crud_date_format'] = 'sql-date';
I tried different web browsers
this is my table and how i update the date and save it to the DB:
$datestring = "%Y-%m-%d";
$time = time();
$data = array(
'Attendence_date_daily' => mdate($datestring, $time),
'Check_in_time' => null,
'Check_out_time' => null,
'Attendence_status' => null,
'Employee_comment' =>null,
'Deducted_today' => 0,
'user_id' => $row->id
);
this is how i created the table
public function edit_daily_record()
{
$crud = new grocery_CRUD();
$crud->columns('daily_record_id','Attendance_date_daily','Check_in_time','Check_out_time','Attendence_status','Employee_comment','Deducted_Today','user_id');
$crud->set_table('daily_attendence_record');
$crud->display_as('Attendance_date_daily','Date')
->display_as('user_id','Employee');
$crud->set_subject('daily record');
$crud->set_relation('user_id','users','username');
$output = $crud->render();
$this->_example_output($output);
}
where 'Attendance_date_daily' is of type date in mysql DB . All fields are shown correctly except this date
'daily_record_id' is auto increment PK
'user_id' is a FK
can you please help me with this problem?
image 1
image 2
I solved this with the help of Mr. Paul Savostin
one of the Advanced members in Grocery CRUD Advance members.
the issue is a simple typo.
the name of the filed in the database is different than the controller by one letter.
this shows how can a letter change the whole code!
Related
This is one of my first applications out of tutorials so I don't know how to express my issue well.
Well I have these 2 tables:
User ( id, code )
Hours ( id, user_id, created)
I want to know how I can add an entry to the Hours table using the user_code.
I tried to grab the data of the User table with the code value and then findBy and pass for the patchEntity but it did not work.
I don't have a whole lot of information to work with, but I'll give it a go.
I want to know how I can add an entry to the Hours table using the
user_code
You mention using patchEntity, so that's updating information that's already there. Assuming user_code is the 'code' column you're talking about there, first find the user by his code:
$users_tbl = TableRegistry::get('Users');
// find the user
$user = $users_tbl->findByCode($user_code)->first();
if ($user) {
// replace '$this->request->data() with whatever patch data you wanted
$users_tbl->patchEntity($user, $this->request->data(), [
'associated' => ['Hours']
]
if ($users_tbl->save($user)) {
// success!
} else {
// error!
}
} else {
// error!
}
It will also depend on how you have the data you passed in (where my '$this->request->data() is, or whatever your array might be) - it needs to match the right column names and be in the correct format listed here.
However, this is updating the data. Just adding the data, you can load the hours table and add a new entry with the user_id acquired from the user search:
$hours_tbl = TableRegistry::get('Hours');
$hours = $hours_tbl->newEntity([
'user_id' => $user->id // $user populated from same method earlier
]);
/* assumed 'id' was autoincrementing and 'created' was populated
through Timestamp behavior */
if ($hours_tbl->save($hours)) {
// yay!
} else {
// boo
}
I have never used sessions before and I am trying to figure out the best way to handle this. I basically am trying to do:
1 step selecting a service
2 step selecting a time
3 step review and book
I can get it to work with no problems using mysql. What I would usually do is save the information into the database after each step and by the time I get to the review part I would have all the information saved and was OK.
However I don't think this is the best way to approach this and might cause problems down the road (what if they stopped at step 2 blah blah)
I decided to try the Laravel 4 sessions and it was super easy to save the session and move on to the next step. However, when I get to the final step I need to join mysql tables to fully show the information about their booking. Can I use the session information to join the information? Can I use the Sessions Database to save this information? Or use different tables?
My controller that POST after reviewing the information:
public function getReview() {
//sets id of user
$user = User::find(Auth::user()->id);
//gets the time and date that they booked from #getSchedule
$scheduler = Session::get('schedule');
//formats time to put in db
$date = strtotime($scheduler['date']);
//same thing as the line above
$dateFormat = date('Y-m-d',$date);
//model to save the schedule
$schedule = new Schedule();
$schedule->userID = $user->id;
$schedule->date = $dateFormat;
$schedule->block = $scheduler['timeslot'];
$schedule->status = "1";
$schedule->save();
//gets the services the user picked from #getServices
$service = Session::get('service');
//saves the services as individual rows in db table
foreach($service as $services)
{
if(!empty($services)) {
$service = new Service();
$service->userID = $user->id;
$service->services = $services;
$service->save();
}
}
return Redirect::to('dashboard');
}
This is the GET review page (where I am having the issues with all the JOINS)
public function showReview() {
$user = User::find(Auth::user()->id);
//show the information and confirm that they want all this crap...if they do..save it and return them to their dashboard
$time = DB::table('bk_schedule')
->leftJoin('bk_timeslot', 'bk_schedule.block', '=', 'bk_timeslot.id')
->where('bk_schedule.id', Auth::user()->id)->first();
$date = strtotime($time->date);
$dateFormat = date('D: F d, Y',$date);
$service = Session::get('service');
$serviceSummary = DB::table('bk_service')
->leftJoin('pr_service', 'pr_service.id', '=', 'bk_service.services')
->where('bk_service.userID', Auth::user()->id)
->get();
$total = DB::table('bk_service')
->leftJoin('pr_service', 'pr_service.id', '=', 'bk_service.services')
->where('bk_service.userID', Auth::user()->id)
->sum('pr_service.price');
return View::make('book.review', array('pageTitle' => 'Booking Appointment Review and Finalize', 'service' => $service, 'date' => $dateFormat,
'time' => $time, 'email' => $user->email, 'serviceSummary' => $serviceSummary, 'total' => $total));
}
Is it possible to save the information at the GET and delete it if they don't submit to POST? Could I maybe use my session data to and use the MySQL queries I have?
You don't understand what the session is, with you approach users will not be able to fill several forms (open in several tabs) simultaneously.
So, general way to do this is:
First page shows just HTML code with some fields
User selects them and POST data back to server
Server validates data and open ANOTHER HTML page with new fields AND adds several "hidden" field with values selected in step 1 (of course server can present page1 with error messages)
Users posts this form, server can open THIRD form where new visible fields and ALL previous fields are stored in hidden inputs
Finally user posts form to last page, where you have all data from all previous pages.
Just to notice: another approach is to store "temporary" data in session, for this you will need to obtain some generated ID on 2nd step and pass it through pages as described before
I want to make an attendance sheet with jqGrid. I'm using PHP and Mysql
I have two tables, one called MemberInfo and one called Attendance.
From the MemberInfo I want to show in the grid the first name and the last name of the member. Then I want to have a box for every day of the week. I want that when I add some data to those fields, for the data to be saved in the Attendance table and also that if I generate the Attendance grid again, the fields that were already filled up, to show the data.
My question is:
How can I add more columns and How can I connect those columns with the Attendance table? Thanks!
EDIT:
I was able to generate new columns and to add the data to the database with cellEdit. Still having problems with generating the grid with the data from 2 tables. Thanks!
I hope this is clear! if its not please let me know! thanks!
(if there is another library for PHP that would make this easier please let me know)
EDIT:
<?php
require_once 'jqgrid/jq-config.php';
// include the jqGrid Class
require_once "jqgrid/php/jqGrid.php";
// include the driver class
require_once "jqgrid/php/jqGridPdo.php";
// Connection to the server
$conn = new PDO("mysql:host=localhost;dbname=db;","root",NULL);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = 'SELECT member_id, first_name, last_name FROM members_info WHERE member_type !=5';
// set the ouput format to json
$grid->dataType = 'json';
$grid->table ="members_info";
$grid->setPrimaryKeyId("member_id");
// Let the grid create the model
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('grid.php');
$grid->cacheCount = true;
// Set grid caption using the option caption
$today = date('Y-m-d');
if(isset($_POST['past_month'])){
$today = date('Y-m-d', strtotime($_POST['past_month']));
}
if(isset($_POST['next_month'])){
$today = date('Y-m-d', strtotime($_POST['next_month']));
}
$days = attendance_cal(date('F', strtotime($today)), date('Y', strtotime($today))); // Gets the days for that month and that year
sort($days); //sort the days
foreach($days as $day){
$grid->addCol(array(
"name"=>date('m-d', $day)
));
}
$grid->setGridOptions(array(
"caption"=>"This is custom Caption",
"rowNum"=>30000,
"sortname"=>"member_id",
"hoverrows"=>true,
"width"=>1000,
"height"=>1000,
"cellEdit"=> true,
"cellsubmit"=>"remote",
"cellurl"=> "cell_dump.php",
"rowList"=>array(10,20,50),
"postData"=>array("grid_recs"=>776)
));
// Change some property of the field(s)
$grid->setColProperty("member_id", array("label"=>"ID", "width"=>60, "editable"=>false));
$grid->setColProperty("first_name", array("label"=>"First Name", "width"=>120, "editable"=>false));
$grid->setColProperty("last_name", array("label"=>"Last Name", "width"=>120, "editable"=>false));
// Enjoy
$grid->navigator = false;
// and finaly bind key navigation
// This is way if no events or parameter
//$grid->callGridMethod('#grid', 'bindKeys');
//
//in case of passing events is better this way
$bindkeys =<<<KEYS
$("#grid").jqGrid('bindKeys', {"onEnter":function( rowid ) { alert("You enter a row with id:"+rowid)} } );
KEYS;
$grid->setJSCode($bindkeys);
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;
?>
Let me be more specific:
My table "Members" has the fields "member_id", "first_name", "last_name"
The "Attendance" table has the fields "attendance_id", "member_id", "attendance_date" ,"attendance_value"
My Grid, I want it to look like:
| Member Id | Name | 03-15-2012 | 03-20-2012 | 03-22-2012 |
The "Member Id" column and "Name" column is being generated from the "Members" table with the SelectCommand, the other columns I'm creating them with addCol. I kinda can figure out how to add data to the database via cellEdit, but when I load the sheet, I dont know how to put the data from the database in the grid besides for the ones coming from the Members table. I hope this is clearer! thanks!
I am assuming you have never used jqGrid and you need to get started...
Please have a look at this link, it gives you demos with code for everything you need to know on how to create your grid using PHP.
http://www.trirand.net/demophp.aspx
I am new to moodle ,currently i am working on questionnaire module, in which we create questionnaire for courses(created by teacher , which are viewed by student on course detailed page there they will answer ) . now i want to know which user created that questionnaire (i.e userid ). I have been searching for while but didnt found any answer.
If the questionnaire table has a createdby field, then you can use that, otherwise, you'll have to do a search through the logs table like this:
// You'll need to get the right coursemoduleid first from the course_modules table
$cmid = 27;
$conditions = array('module' => 'questionnaire',
'coursemoduleid' => $cmid,
'action' => 'add');
$creationrecord = $DB->get_record('log', $conditions);
$creator = $creationrecord->userid;
The documentation for Netsuite is quite lacking, they cover the basics and then let you loose to explore. Anyone without a vast knowledge of PHP trying to use their php toolkit would be on their knees begging for mercy.
At any point throughout this whole project it's been trail and error and trying to make sense out of everything until stuff started to work.
I'm stumped on assigning custom fields to sales orders, I know it has to be an object of an object of an object in order for it to tier down the xml for the soap to take over but what with what with what?
I have some code I worked that is getting somewhere but it is complaining it's not the right RecordRef type. If anyone worked with Netsuite and feels my pain please lend me your knowledge before I pull out all my hair.
Thanks in advance.
Code:
$customFields = array('internalId' => 'custbody_new_die_yn','value' => array('name' => 'custbody_new_die_yn','internalId' => 'NO'));
$customObject = new nsComplexObject("SelectCustomFieldRef");
$customObject->setFields($customFields);
$salesOrderFields = array(
'entity' => new nsRecordRef(array('internalId' => $userId)),
'paymentMethod' => array('internalId' => 8),
'ccNumber' => 4111111111111111,
'ccExpireDate' => date("c", mktime(0,0,0,11,1,2011)),
'ccName' => 'Test Testerson',
'itemList' => array(
'item' => array(
'item' => array('internalId' => 5963),
'quantity' => 5
)
),
'department' => new nsRecordRef(array('internalId' => 1)),
'class' => new nsRecordRef(array('internalId' => 47)),
'customFieldList' => $customObject
);
I am not familiar using PHP with Netsuite but I have done a good amount of c#/.net Netsuite work. As Craig mentioned I find it much easier using a language such c#/.net with a Visual Studio generated interface to figure out what is available in the Netsuite SuiteTalk web service API.
There is a fair amount of documentation around this stuff in the NetSuite Help Center - by no means everythign you will need but a good start. Netsuite Help Center
Check out the SuiteFlex/SuiteTalk (Web Services) section specifically this page on Ids & References.
Using Internal Ids, External Ids, and References
With that said I will try to help with a .net example & explanation of adding a custom field to a Sales Order.
Here are a few examples of adding different CustomFieldRefs:
//A list object to store all the customFieldRefs
List<CustomFieldRef> oCustomFieldRefList = new List<CustomFieldRef>();
//List or Record Type reference
SelectCustomFieldRef custbody_XXX_freight_terms = new SelectCustomFieldRef();
custbody_XXX_freight_terms.internalId = "custbody_XXX_freight_terms";
ListOrRecordRef oFreightTermsRecordRef = new ListOrRecordRef();
oFreightTermsRecordRef.internalId = <internalId of specific record in Netsuite>;
//See the References link above for more info on this - trying to figure out typeId caused me a lot of pain.
oFreightTermsRecordRef.typeId = <internalId of the List Record Type in Netsuite>;
custbody_XXX_freight_terms.value = oFreightTermsRecordRef;
oCustomFieldRefList.Add(custbody_XXX_freight_terms);
//Freeform text sorta field
StringCustomFieldRef objStringCustomFieldRef = new StringCustomFieldRef();
objStringCustomFieldRef.internalId = "custbody_XXX_tracking_link";
objStringCustomFieldRef.value = "StringValue";
oCustomFieldRefList.Add(objStringCustomFieldRef);
//Checkbox field type
BooleanCustomFieldRef custbody_XXX_if_fulfilled = new BooleanCustomFieldRef();
custbody_XXX_if_fulfilled.internalId = "custbody_XXX_if_fulfilled";
custbody_XXX_if_fulfilled.value = true;
oCustomFieldRefList.Add(custbody_XXX_if_fulfilled);
//By far the most complicated example a multi-select list referencing other records in Netsuite
MultiSelectCustomFieldRef custrecord_XXX_transaction_link = new MultiSelectCustomFieldRef();
//internal id of field you are updating
custrecord_XXX_transaction_link.internalId = "custrecord_XXX_transaction_link";
List<ListOrRecordRef> oListOrRecordRefList = new List<ListOrRecordRef>();
ListOrRecordRef oListOrRecordRefItemFulfillment = new ListOrRecordRef();
oListOrRecordRefItemFulfillment.name = "Item Fulfillment";
oListOrRecordRefItemFulfillment.internalId = <ItemFulfillmentInternalId>;
//Item Fulfillment is record type (Transaction -30) - this is from the above Reference links
oListOrRecordRefItemFulfillment.typeId = "-30";
oListOrRecordRefList.Add(oListOrRecordRefItemFulfillment);
ListOrRecordRef oListOrRecordRefSalesOrder = new ListOrRecordRef();
oListOrRecordRefSalesOrder.name = "Sales Order";
oListOrRecordRefSalesOrder.internalId = <SalesOrderInternalId>;
//Sales Order is record type (Transaction -30) - this is from the above Reference links
oListOrRecordRefSalesOrder.typeId = "-30";
oListOrRecordRefList.Add(oListOrRecordRefSalesOrder);
//Add array of all the ListOrRecordRefs to the MultiSelectCustomFieldRef
custrecord_XXX_transaction_link.value = oListOrRecordRefList.ToArray();
oCustomFieldRefList.Add(custrecord_XXX_transaction_link);
//And then add all these to the Custom Record List (Array) on the Sales Order Record
objSalesOrder.customFieldList = oCustomFieldRefList.ToArray();
From what I can tell in your above example I think your issue is with the ListOrRecordRef typeId. Its hard to tell from your example what typeId you are referencing but if you can figure that out and set the TypeId on your SelectCustomFieldRef I think that should fix your issue.
The Custom Field Ref Internal ID is the reference ID on the record you are trying to update. This can be found in the Transaction Body fields for that record within Netsuite.
The Internal ID for the ListOrRecordRef is the internal ID for the actual list item or record that you want to attach to the previously mentioned record
The typeID for the ListOrRecordRef is the internal ID for the custom list/record. This is the parent ID for the previous internal ID, and is not inherently tied to the original record.