Cannot Update Dynamic Fields in Codeignitor - php

I created Dynamic fields for billing information,item name,qty,rate,total fields are loaded dynamicall by click Add New.When i want to update active records in dynamic fields there some Database Error.
Any For loop issue or anyone suggest--Cheers!
public function updatebill(){
$currentBillId=$this->input->post('bill_no');
$update_billno=$this->input->post('itemData[1[bill_no]');
$updatePostData=$this->input->post('itemData');
$this->load->model('billmodel');
$this->billmodel->update_bill_details($currentBillId,$updatePostData);
}
I have checked $cuurentBillId(having bill Id),$updatePostData(having input fields data which i want to update on the table)
public function update_bill_details($currentBillId,$updatePostData){
$bill_no=$this->input->post('itemData[1[bill_no]');
$item_name=$this->input->post('itemData[1][item_name]');
$item_quantity=$this->input->post('itemData[1][item_quantity]');
$item_rate=$this->input->post('itemData[1][item_rate]');
$item_total=$this->input->post('itemData[1][item_total]');
$item_tax=$this->input->post('itemData[1][item_tax]');
$without_tax=$this->input->post('itemData[1][without_tax]');
$item_grand_total=$this->input->post('itemData[1][item_grand_total]');
$item_income_tax=$this->input->post('itemData[1]item_income_tax');`for($i=1;$i<sizeof($updatePostData); $i++)`
{
$result=array(
'item_name'=>$item_name,
'item_quantity'=>$item_quantity,
'item_rate'=>$item_rate,
'item_total'=>$item_total,
'item_tax'=>$item_tax,
'without_tax'=>$without_tax,
'item_grand_total'=>$item_grand_total,
'item_income_tax'=>$item_income_tax);
$this->db->where('bill_no',$i);$this->db->set($result[$i]);
}

Related

Creating an auto incremented id when user submits a form

Currently I have a refno. column in my database with the format LP00001. Now I have a add page that inserts all data that the user inserts in the input field and all this data gets sent to a table in my database, but my refno column stays null which I want to have an auto incrementing value where the last 5 digits will be +1 everytime the user submits the form.
I do not want to have it be shown before the submit button as 2 users can be on that page at the same time which means they both will get the same id which means it has to generate it only at the time of submit. Currently this is my code:
Controller class:
if ($this->form_validation->run() == FALSE)
{
$main['page'] = 'crm/listings/add';
$this->load->view('crm/index', $main);
}else {
$maindata=array('clients_id'=>$this->session->userdata('clientsessid'),
'property_for'=>$this->security->xss_clean($this->input->post('property_for')),
'property_type'=>$this->security->xss_clean($this->input->post('property_type')));
$insertid=$this->listings_model->insert_listing($maindata);
if($insertid){
$this->session->set_flashdata('message', '<div>Successfully</div>');
redirect('listings/sales');
Model Class:
function insert_listing($maindata){
$this->db->insert("crm_listings",$maindata);
$prime=$this->db->insert_id();
return $prime;
}
So I assume I'll need to do this in my model class function insert_listing since that is called when I press submit button. Here another thing will be that the model will have to check what was the last entry in the database that has to be incremented for which I'm assuming I'll have to use echo str_replace("LP","","LP00001");
I guess you just have to prepend the initials LP to the returned autoIncremented id.
function insert_listing($maindata){
// ...
$this->db->set("refno", "LP". sprintf('%05d', $prime));
$this->db->where('id', $prime);
$this->db->update("crm_listings");
return $prime;
}

Add row to HTML table with Laravel Livewire - Issue

Firstly I'm new to Laravel and this is my first post. Please forgive me if I'm doing things wrong.
I have an HTML table, which is a Livewire component. In this HTML table, each row has a dropdown box and some text fields. This is for a timesheet application. The dropdown is the job and there are 7 text boxes, for each day of the week for the hours to be entered.
I have tried to include an Add button, I want this to add a new row at the end of the HTML table.
The issue I'm getting is when I click on Add, it will append the row, however, my dropdown is not shown, UNTIL I refresh the page, then it appears as it should.
The way I currently have my program is that when a user clicks on add, it will create a new record in my Entries table, with the timesheet ID included, and the rest of the values as null. Is there another way of temporarily storing the lines the user creates, then commit to the database? Is there a way to refresh my table so that it displays the new line correctly?
Please let me know if you need further details or a better explanation of my issue.
My code is as follows:
Controllers\Livewire\ShowTimesheet.php
...
public function mount($entries)
{
$this->entries = $entries;
}
public function render()
{
return view(‘livewire.show-timesheet');
}
public function add($i)
{
$entries_new = new Entries;
$entries_new->timesheet_id = $i;
$entries_new->save();
$new = array(
'id'=>$entries_new->id,
'timesheet_id'=>$i,
'job_id'=>null,
'worktype_id'=>null,
'hours_sun'=>null,
'hours_mon'=>null,
'hours_tue'=>null,
'hours_wed'=>null,
'hours_thu'=>null,
'hours_fri'=>null,
'hours_sat'=>null,
);
$this->entries[] = $new;
}
...
Layouts\livewire\show-timesheet.blade
...
#foreach($timesheet as $sheet)
...
<div wire:click="add({{$sheet['id']}})" class='cursor-pointer'>
...
#endforeach
...

Create gravity form poll based on post types

Is there a way to create/update form poll fields based on a content type? For example, I've got a post type called Candidate and I'd like like to dynamically update a poll list when a new Candidate is added, or when one is removed.
The reason I'm looking for this is because I'm creating a voting mechanism for this client and they have requested that users see an image, the name, and brief Bio of who they are voting for. My idea is to tie in the names so that I can target a hidden Gravity Form poll on page so when the voter clicks, it updates the corresponding named checkbox.
I can of course add each Candidate one by one, and then add each candidate one by one in the form, but was hoping there was a way to do that in code. So far I haven't found much other than filters in the Gravity Forms Documentation.
To reiterate, my question here is not the frontend connection, rather how to dynamically update/add an option in a poll field in a form when content is created for a Candidate post type.
Any help would be appreciated.
I believe the solution you're after is documented here:
http://www.gravityhelp.com/documentation/gravity-forms/extending-gravity-forms/hooks/filters/gform_pre_render/
Probably a combination of solution examples #1 and #2 on that page will fit your needs? So -
Create a category of standard Wordpress pages (category name: "Candidates"), and the pages would contain the candidate information (bio, photo, etc).
In your functions.php file for your current theme, you'd add something like the following to pull out that category's worth of posts:
// modify form output for the public page
add_filter("gform_pre_render", "populate_checkbox");
// modify form in admin
add_filter("gform_admin_pre_render", "populate_checkbox");
function populate_dropdown($form) {
// some kind of logic / code to limit what form you're editing
if ($form["id"] != 1) { return $form; }
//Reading posts for "Business" category;
$posts = get_posts("category=" . get_cat_ID("Candidates"));
foreach ($form['fields'] as &$field) {
// assuming field #1, if this is a voting form that uses checkboxes
$target_field = 1;
if ($field['id'] != $target_field) { break; }
// init the counting var for how many checkboxes we'll be outputting
// there's some kind of error with checkboxes and multiples of 10?
$input_id = 1;
foreach ($posts as $post) {
//skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
if($input_id % 10 == 0) { $input_id++; }
// here's where you format your field inputs as you need
$choices[] = array('text' => $post->post_title, 'value' => $post->post_title);
$inputs[] = array("label" => $post->post_title, "id" => "{$field_id}.{$input_id}");
// increment the number of checkboxes for ID handling
$input_id++;
}
$field['choices'] = $choices;
$field['inputs'] = $inputs;
}
// return the updated form
return $form;
}

Saving Checkboxlist data and retrieving User's last checked items when creating new Record

I have a Product model with a 'categories' column. This column should be able to contain data from a Checkboxlist.
Whenever a user creates a new Product I want the form to display the 'categories' Checkbox, with the items set as active from the user's last created Product.
So for instance: the 'categories' Checkboxlist contains items 'Movies' and 'Music'. When the user checks 'Movies' and creates the Product, the next time the user goes to create a Product, 'Movies' is already selected (because it saves the selection from the user's previous product creation).
I believe these are the most effective steps to code in order to achieve this goal:
When Product is created: checked items are saved to 'categories' column in Product Model & a 'categories' column in the User's 'Profile' model
User's last saved categories ('categories' column in Profile model) should be retrieved at the Product's Create form.
Code in Product model's _form view:
<?php echo $form->checkBoxList($model, 'categories', array('movies'=>'Movies','music'=>'Music')); ?>
(I'm unsure as to where to set an array for active values)
I'll need to convert the Array of the selected Checkboxes to a string using explode(",", $model->categories) so I can put it inside the 'categories' columns of the 'Product' and 'Profile' models by using the ProductController's actionCreate function.
Then to set the user's last selected Checkboxlist items as active in the Product _form view I need to convert the $model->categories data back to an array by imploding the column ie implode(",", $user->profile->categories).
How would you code this in Yii?
Use CHtml::ckeckboxList instead of activecheckbox.
It have selected parameter. Selected there is array of key=>value pairs. yiiframework.com/doc/api/1.1/CHtml#checkBoxList-detail
Or you can rewrite (extend) you CHtml helper to resolve your format.
For example:
public static function activeCheckBoxList($model,$attribute,$data,$htmlOptions=array())
{
self::resolveNameID($model,$attribute,$htmlOptions);
if(array_key_exists('explode_format',$htmlOptions))
{
$selection=explode($model->$attribute);
unset($htmlOptions['explode_format']);
}
else{
$selection=self::resolveValue($model,$attribute);
}
if($model->hasErrors($attribute))
self::addErrorCss($htmlOptions);
$name=$htmlOptions['name'];
unset($htmlOptions['name']);
if(array_key_exists('uncheckValue',$htmlOptions))
{
$uncheck=$htmlOptions['uncheckValue'];
unset($htmlOptions['uncheckValue']);
}
else
$uncheck='';
$hiddenOptions=isset($htmlOptions['id']) ? array('id'=>self::ID_PREFIX.$htmlOptions['id']) : array('id'=>false);
$hidden=$uncheck!==null ? self::hiddenField($name,$uncheck,$hiddenOptions) : '';
return $hidden . self::checkBoxList($name,$selection,$data,$htmlOptions);
}
Then just add 'explode_format'=>true to your htmloptions for activecheckboxlist. Something like this will work.

how do I exclude table field MYSQL

Sorry about the strange title, but I am having a small issue if the user type is 2 or 3 then I need the user not to be able to insert or update a few fields, but instead of creating a number of insert queries listed below are a few fields I need not updated.
AMStatus,HQStatus,approvedforsite
public function databaseinsert($data)
{
$this->data = $data;
switch($this->data['action']){
case "newlead":
$this->insert("customer_detail",
"TradingName,Street,City,State,PostCode,Industry,SubCategories,Membership,LeadStatus,AMStatus,HQStatus,approvedforsite,Salutation,FirstName,LastName,Website,Company,ABN_ACNNumber,Phone,Mobile,Notes,Description",
"'{$this->data['tradingname']}',
'{$this->data['street']}',
'{$this->data['suburb']}',
'{$this->data['state']}',
'{$this->data['postcode']}',
'{$this->data['category']}',
'{$this->data['subcategory']}',
'{$this->data['membership']}',
'{$this->data['salestatus']}',
'{$this->data['managerstatus']}',
'{$this->data['hqstatus']}',
'{$this->data['publishtoweb']}',
'{$this->data['title']}',
'{$this->data['firstname']}',
'{$this->data['lastname']}',
'{$this->data['webaddress']}',
'{$this->data['companyname']}',
'{$this->data['abnacn']}',
'{$this->data['phonenumber']}',
'{$this->data['mobile']}',
'{$this->data['notes']}',
'{$this->data['businessdescription']}'
");
break;
}
}
You need to do it in your script handle database fields and values by applying conditions. and make strings of both according to different user types before applying them in $this->insert function.
Something like below:
if($usertype=='yourtype')
{
$fieldsstr="TradingName,Street,City.................";
$valuestr=$this->data['tradingname'].",".$this->data['field2'].",".......
}
else
$fieldsstr="TradingName,Street.................";
$valuestr=$this->data['tradingname'].",".$this->data['field2'].",".......
}
$this->insert("customer_detail",$fieldsstr,$valuestr);

Categories