Mysql temporary database in codeigniter? - mysql

i have a deployment to do within 2 days time and for the last three days i have been busy trying to understand this one thing am stuck in. It probably might be very silly of me but please take me as a newbie.
I am using an opensource software php opensource pos and it is made on CI. Now the issue is that the reports in the application are different than what my client wants. I want to change that to the way they want it but i cant.
this is the code:
$this->db->select('sale_date, sum(total) as total, sum(profit) as profit');
$this->db->from('sales_items_temp');
if ($inputs['sale_type'] == 'sales')
{
$this->db->where('quantity_purchased > 0');
}
elseif ($inputs['sale_type'] == 'returns')
{
$this->db->where('quantity_purchased < 0');
}
$this->db->group_by('sale_date');
$this->db->having('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"');
$this->db->order_by('sale_date');
return $this->db->get()->result_array();
every thing is working fine and as expected. Now i need to make some changes but the issue is i cannot find the temp database to see which fields it has. This database table (the temp one) is being used in all the reports functions, same database.
Can some one be so helpful and explain me the way it works, or how is that i can make a change to it!?
The scenario is that it is giving a summary of all the sales in the selected date range as total. I want a break down in terms of cash, credit, credit card, debit card etc.
I have another report which shows that, but not in date wise as in not saying how much in which day but in total of the date range. This one gives the total as in total sales in a day but not the break up of it as in what was what.
You can login here first:
https://demo.phppointofsale.com/index.php/login (id and password is saved on the page)
Then you can paste this link on the address bar and see the report.
https://demo.phppointofsale.com/index.php/reports/summary_sales/1969-12-31/2012-03-13/all/0
I need it to be a breakdown of the total and remove the tax, profit and subtotal columns and change that with the kind of payment as in cash | credit | cheque etc and then a total for that day.
PS: I am sorry for such a big writing but i am really stuck, please help me out. Thank you in advance.

The table name is sales_items_temp.
To see the actual database config (for database name, host, etc), look in either /system/application/config/database.php or /application/config/database.php depending on the version of Codeigniter.
To see about changing the query, check out http://codeigniter.com/user_guide/database/active_record.html.

Related

How can I correct this code to be able to get a difference in weights for each client?

I am working in MS Access. My end goal is a database report that shows the total amount lost so far for each client, based on the texts they send in daily. I've been able to extract the number from the message, but I need to be able to have a running report each day with how much they've lost since they first texted in. I tried this solution with no success: Access SQL Query: Find the most recent date entry for each employee for each training course
After that, I'v been working with the code from here: https://www.techonthenet.com/access/queries/weight.php. I've tried to write a query that brings up the Last Visit Date, but I keep getting type mismatches with this:
DMax("LogDate","NumberQ","TargetFK=" & TargetFK)
NumberQ is a query, where columns are TargetFK (Short text), FirstName (Short text), LastName (short text), LogDate (Date), Message (short text), and Weight (calculated field).
My question is, what am I doing wrong, and is there a better way to do it?
Since TargetFK is a text field, you need quotations around it:
DMax("LogDate","NumberQ","TargetFK='" & [TargetFK] & "'")

Aggregate function in group header?

I have a really simple recordset by the name of qryUserFiles:
string: [UserID], [ftype]; Long: [fsize]
(records are file-information details of each file in each users' userfolder on the file-server)
I have created a report which lists the sum of [fsize] for each [UserID] by grouping on [UserID] and putting =Sum([fsize]) in a textbox in the header of the group. So far so good. So that shows me the total size of that user's user-share on the fileserver. (Helpful with respect to both convincing the users to clean up their stuff, and convincing the executives that we need to buy more storage!)
Now the headbanging part.
I want to add, in that same header, various textboxes containing the sum of the [fsize] for various values of [ftype]. So, for example, I'd want the sum of [fsize] for files where ftype="jpg" for each UserID. (And then another sum of [fsize] for files where ftype="mov" for each UserID, and so on for various 'problematic' file-types!)
I tried putting a
Dsum("fsize","qryUserFiles","ftype='jpg'")
in the group header, but, as expected, it is looking at the entirety of the 'qryUserFiles' recordset, and giving me the domain-total of size for jpg, not the this-user-total of size for jpg.
I considered trying to add something to the 'where' clause of the dsum function that would include 'this' user as criteria, but how would I refer to 'this' userID, with respect to the grouping-pointer?
Or is there a way easier way to do what I want without going nuts!? Would this be easier in another query? I feel like there's a simple, obvious answer just out of reach!
(I'm hoping to avoid brute-force VBA code to step through the table record by record, and calculate the stats with Dsum and add them to a new table. But if that's how to do this....)
I think - judging from what I read - you just need to let the report do its stuff. You can group on user and ftype - including the totals in the details and the totals in the Group Footer
You definitely should not use a DSum formula

Searching Between dates where STOP date is null

I need your help.
The following is my database table.
http://i42.tinypic.com/10xh4j7.png
A small request to please have a look at the image.
My problem is, when I want to retrieve the rate from date_from and date_to.
For Eg: Lets say retrieving_date = 2013-11-14.
rs = stat.executeQuery("select rate from rate_chart where '"+retrieving_date+"' BETWEEN date_from AND date_to");
This query gives me my required result, for the 11th month.
I get 10.40 as my required rate with the above query.
Lets say, rate has never been changed since 2013-11-26, and now my retrieving_date is 2013-12-20. And now, when I try to execute the above query, it doesn't work. No errors but doesn't give me the last rate. In my case, is 10.80 as mentioned in the above image.
I actually want to search between dates even if the stop date or (date_to) is null.
No, idea how to go forth with this. Stuck for a while now.
Any help would be greatly appreciated.
if the stop date (or date_to) is null, set it to the current date.

Check to see if one year has passed

I run a web design firm, and we also sell hosting on a yearly basis to our customers. I'm writing a Ruby script to read all of the customers from a MySQL database and check to see if a year has passed. If it has (or is at least close to expiring), I want it to send an Email to them.
I have the Emailing part down, but how would I check to see if one year has passed using the Time class, or another solution based in SQL?
(looking back with this edit, it seems as though I don't quite know the SQL needed, so any help on that is appreciated)
If you really want to solve this issue using ruby you can use >> when dealing with a Date to increment it by N months (such as 11, which will give your customers some time to deal with the payment).
When you've got this incremented date you should compare it to what the current date is to see if it's less or equal (ie. the date is in the past), if so; send out your email.
>> (Date.strptime('2012-07-07') >> 11).to_s
=> "2013-06-07"
>> if (Date.strptime('2011-06-15') >> 11) < DateTime.now
>> print "More than 11 months has passed!"
>> end
More than 11 months has passed!=> nil
Though, you are much better of solving this issue directly in the SQL query, which would boil down to something as the below:
SELECT field1, field2, ..., fieldN
FROM `customers_table`
WHERE ADDDATE(last_payment, INTERVAL 11 MONTHS) <= NOW ()

grab mysql result based on field values

I am taking over designing a CMS from another programmer. As the site is filling up, we're finding loops in mysql queries causing long hangs. I have found a temp solution for this one, but am wondering if there is a quicker way of doing it?
take the table (tracks resources):
id resource click
1 res_1 192
2 res_2 12
3 res_3 300
what we need to get is a popularity of the resource - res_click/total_click
what he had was a while loop:
while ($item = mysql_fetch_array ($result)) $total_clicks = $total_clicks + $item[0];
As there could be 100 or more resources to a page, this was running for each resource, and it is causing major hangs.
My solution is to get a sum:
SELECT SUM(click) FROM uri
SELECT click FROM resource WHERE id=$x
then divide them both.
But this two calls are still running for around a 100 items per page. Is there a way I can have a field in mysql that is the result of a formula based on another another, like in excell? So I could add a field "percentage", tell mysql that it is the sum of click divided by the current click value, then every time click is updated the 'percentage' field is automatically updated?
any help would be appreciated,
cheers ;)
you can create a view on your table that present the sum you want