CakePHP 3 - Export CSV controller function missing - twitter-bootstrap-3

I feel I followed the instructions for https://github.com/FriendsOfCake/cakephp-csvview.
1.I add public function export() to my controller.
public function export() {
$this->response->download('export.csv');
$data = $this->EstimatedRevenueFromCourseFees->find('all')->toArray();
$_serialize='data';
$_header = ['Semester', 'Total # of courses in the course bank', 'Total # of courses with approved fees', '# of courses offered', '% with fees', '# of courses with $100 & under', '% of courses with fees $100 & under', ' Revenue from $100 & under',
'# of courses with $100 & over', '% of courses with fees $100 & over', 'Revenure from $100 & over', '% of courses with fees $100 & over', 'Revenue from $100 & over', 'Total Revenue from course fees'];
$this->set(compact('data','_serialize','_header'));
$this->viewBuilder()-className('CsvView.Csv');
return;
}
installed plugin using composer and added to bootstrap.php:
Plugin::load('CsvView');
added this to routes.php:
Router::extensions('csv');
added this to my view file:
<?= $this->Html->link('export', ['controller'=>'estimatedRevenueFromCourseFees', 'action'=>'export', '_ext'=>'csv'], ['class'=> 'btn btn-success']) ?>
But when I hit the button I get the
Error: Create EstimatedRevenueFromCourseFeesController::export.csv()
Not sure what I'm missing. It does not seem to recognize the export function keeps added the .csv which I thought the router statement would adjust for.

Related

Google Analytics - Incorrect Revenue (refunds)

I've noticed that the product revenue shows incorrect values.
Example:
The user buys
3000 HUF item (qty: 2)
The total is 6000 HUF
The user refunds one item
So -3000 HUF
The revenue should be 3000 now, but it is still 6000... what do I do wrong?
You see, the Product Refund Amount is correct, but the Product Revenue is not:
My refund code:
gtag('event', 'refund', {
'transaction_id': 'ID',
'value': "3000",
'currency': 'HUF',
'items': [{
'id': '01',
'name': 'PRINGLES',
'quantity': 1,
'price': '3000',
}]
});
This is also the same case as when I refund a whole order.
I believe in financial terms 'revenue' (or 'total revenue') is the total of sales, including the amount that was refunded. What you're looking for is the 'net revenue', which is not directly available in GA sales performance report.
You'll need to create a calculated metric where you subtract the refund amount from product revenue. Here is the documentation: https://support.google.com/analytics/answer/6121409?hl=en

Calculate freight total in a computed field on Invoice - Odoo

I am trying to get a freight total to show on the bottom of my invoices. I created a new field in the Accounting Module called "Freight Total" (x_studio_freight_total). I want to get the sum of the "Subtotal" (price_subtotal) for any instance where the "Product" (product_id) = "FREIGHT".
For the field, x_studio_freight_total, I set the Dependencies as: "invoice_line_ids.price_subtotal, invoice_line_ids.product_id"
I set the Compute property as:
for record in self:
if(record.invoice_line_ids.product_id == "FREIGHT):
record['x_studio_freight_total'] = sum(record.invoice_line_ids.price_subtotal)
If an invoice shows a line with a 'Product' named "FREIGHT", and a 'Subtotal' of "12.75" I expect my 'Freight Total' field to display "12.75".
If an invoice has two lines with 'Product' named "FREIGHT, one with a 'Subtotal' of "12.75" and the other with a 'Subtotal' of "7.50", I expect the 'Freight Total' field to display "20.25".
But it currently is not displaying anything just "0.00"
Try using this code
for record in self:
record['x_studio_freight_total'] = 0
for line in record.invoice_line_ids:
if(line.product_id.name == "FREIGHT): #product_id.name to search product name
record['x_studio_freight_total'] += line.price_subtotal`

MS Access extracting elements from multi-valued field based on condition

I get a report where there is a multi-valued field that houses user roles and the respective user information. There are a total of 6 roles and each row of data could have multiple people operating under the same role. I am using MS Access 2013 to do my data manipulation.
ID Data Users
1 Data1 Supervisor (MICROSOFT OUTLOOK; microsoftoutlook#example.com 9999999999) Admin Assistant (WATER BOTTLE; waterbottle#example.com, 9999999999) Analyst (GREEN BLUE; greenblue#example.com; 999999999)
2 Data2 Supervisor (COMPUTER MONITOR; computermonitor#example.com; 9999999999) Admin Assistant (MICROSOFT EXCEL; microsoftexcel#example.com, 9999999999) Analyst (GREEN BLUE; greenblue#example.com; 999999999); Analyst (ORANGE PURPLE; orangepurple#example.com; 999999991)
3 Data3 Supervisor (GREEN BLUE; greenblue#example.com; 9999999999) Admin (MICROSOFT ACCESS; microsoftaccess#example.com, 9999999999) Analyst (ORANGE PURPLE; orangepurple#example.com; 999999999); Analyst (YELLOW BLACK; yellowblack#example.com; 999999991)
The above is a truncated and substituted data set. In ID = 2 and 3, there are 2 analysts. There could be a case where there are 2 "Admin Assistants". The formatting for the Users is exactly as listed. Individual users could be listed across multiple rows as well and under different roles sometimes.
I don't necessarily need to split the data apart, but I do need pick out certain roles based on the Data column. If Data = [Certain Condition], then pull in a certain user role. For example, if Data = "Completed", I need to pull all the "Supervisors" for that row. If Data = "In progress", I need to pull all the "Analysts" for that row. There are other conditionals too for determining which role and users to pull. I need to pull both the user role and the users associated with that role for that row. I would like to create 2 new columns for "Ownership Role" and "Current Ownership". "Ownership Role" is the User Role and "Current Ownership" should contain all the users associated with that role for that row.
Please let me know if you have any questions or need any clarification. I appreciate you taking the time to read this.
UPDATE
My desired results are below.
ID Data Ownership Role Current Ownership Users
1 Completed Supervisor MICROSOFT OUTLOOK Supervisor (MICROSOFT OUTLOOK; microsoftoutlook#example.com 9999999999) Admin Assistant (WATER BOTTLE; waterbottle#example.com, 9999999999) Analyst (GREEN BLUE; greenblue#example.com; 999999999)
2 In Progress Analyst GREEN BLUE, ORANGE PURPLE Supervisor (COMPUTER MONITOR; computermonitor#example.com; 9999999999) Admin Assistant (MICROSOFT EXCEL; microsoftexcel#example.com, 9999999999) Analyst (GREEN BLUE; greenblue#example.com; 999999999); Analyst (ORANGE PURPLE; orangepurple#example.com; 999999991)
3 Initiated Admin MICROSOFT ACCESS Supervisor (GREEN BLUE; greenblue#example.com; 9999999999) Admin (MICROSOFT ACCESS; microsoftaccess#example.com, 9999999999) Analyst (ORANGE PURPLE; orangepurple#example.com; 999999999); Analyst (YELLOW BLACK; yellowblack#example.com; 999999991)
UPDATE 2019-05-10
Due to my failure to properly explain the question and set up a sample data set, I am posting the cases based on June7's answer and a sample row of data.
Case "Initiated"
strRole = "Main Admin Assistant"
Case "Drafted"
strRole = "Financial Analyst"
Case "Rated"
strRole = "Contractor Rep"
Case "Reviewed"
strRole = "Assessing Official"
Case "Finalized"
strRole = "Reviewing Official"
Sample Data - this is all in 1 cell in Excel and each element is on a different line in that cell. Immediately after the close parenthesis, there is NO space from what I can tell so the next user role begins IMMEDIATELY.
Supervisor (ERGO KB; ergokb#example.com; (999) 999-9999)Team Lead (WIDE SCREEN; widescreen#example.com; 9999999999)Team Rep (CELL PHONE; cellphone#example.com; 999-999-9999)Team Rep (CLICK PEN; clickpen#example.com; (999) 999-9999)Main Admin Assistant (WIRED MOUSE; wiredmouse#example.com; 999-999-9999)Main Admin Assistant (PHONE CHARGER; phonecharger#example.com; 9999999999)Financial Analyst (WATER BOTTLE; waterbottle#example.com; (999) 999-9999)Financial Analyst (CLEAR TAPE; cleartape#example.com; 999-999-9999)Human Resources (POST IT NOTE; postitnote#example.com; 999-999-9999)
For each status below, I want the associated User Role.
Status User Role
Initiated Main Admin Assistant
Drafted Financial Analyst
Rated Team Rep
Reviewed Financial Analyst
Finalized Human Resources
Completed Completed
Real Desired Results
Status User Role Users
Initiated Main Admin Assistant WIRED MOUSE, PHONE CHARGER
Drafted Financial Analyst WATER BOTTLE, CLEAR TAPE
Rated Team Rep CELL PHONE, CLICK PEN
Reviewed Financial Analyst WATER BOTTLE, CLEAR TAPE
Finalized Human Resources POST IT NOTE
Completed Completed Completed
Consistency in structure is critical when parsing strings. For instance, there is a semi-colon after ) between the last two elements of IDs 2 and 3 but no semi-colon after the others. That extra semi-colon complicates programming logic. Since comments say that semi-colon is a typo as well as no space following ), code reflects those corrections in structure.
Here is a function to get you started. Place this procedure in a general module and it can be called from query or textbox.
Function GetUsers(strData As String, strUsers As String) As String
Dim aryS As Variant, x As Integer, strRole As String, strNames As String
aryS = Split(strUsers, ")")
Select Case strData
Case "Initiated"
strRole = "Main Admin Assistant"
Case "Drafted"
strRole = "Financial Analyst"
Case "Rated"
strRole = "Team Rep"
Case "Reviewed"
strRole = "Financial Analyst"
Case "Finalized"
strRole = "Human Resources"
End Select
For x = 0 To UBound(aryS) - 1
If strRole = Left(aryS(x), InStr(aryS(x), "(") - 2) Then
strNames = strNames & Mid(aryS(x), InStr(aryS(x), "(") + 1, InStr(aryS(x), ";") - 1 - InStr(aryS(x), "(")) & ", "
End If
Next
If strNames <> "" Then GetUsers = Left(strNames, Len(strNames) - 2)
End Function
Instead of determining Role by calculation with Data, suggest a table that defines these associations. Include that table in query then pass the Role to function instead of Data and the Case block should not be needed.
Revised code to deal with inconsistent phone number structure that sometimes has parens causing previous code to fail as well as the possibility of similar role names (I probably should have gone this way to begin with):
Function GetUsers(strData As String, strUsers As String) As String
Dim strRole As String, strNames As String
Select Case strData
Case "Initiated"
strRole = "Main Admin Assistant ("
Case "Drafted"
strRole = "Financial Analyst ("
Case "Rated"
strRole = "Team Rep ("
Case "Reviewed"
strRole = "Financial Analyst ("
Case "Finalized"
strRole = "Human Resources ("
Case "Completed"
strRole = "Financial Analyst Jr ("
End Select
Do While InStr(strUsers, strRole) > 0
strUsers = Mid(strUsers, InStr(strUsers, strRole))
strNames = strNames & Mid(strUsers, InStr(strUsers, "(") + 1, InStr(strUsers, ";") - Len(strRole) - 1) & ", "
strUsers = Mid(strUsers, 2)
Loop
If strNames <> "" Then GetUsers = Left(strNames, Len(strNames) - 2)
End Function

Cart discount on Virto Commerce Marketing Module

I would like to do a promotion in Virto Commerce on the cart. In my example i would like to discount the cart with 200 SEK if the customer buys for at least 800 SEK, the VAT/GST in my example is 25%.
This is the effect I'm looking for:
Cart
subTotal: 640
subTotalWithTax: 800
discountAmount: 160
discountTotalWithTax: 200
total: 480
totalWithTax: 600
As far as i can tell the Marketing Module only supports promotions where the discount is applied before taxes. Se comment in storefront code:
ShoppingCart.cs#L390
foreach (var reward in cartRewards)
{
//When a discount is applied to the cart subtotal, the tax calculation has already been applied, and is reflected in the tax subtotal.
//Therefore, a discount applying to the cart subtotal will occur after tax.
//For instance, if the cart subtotal is $100, and $15 is the tax subtotal, a cart - wide discount of 10 % will yield a total of $105($100 subtotal – $10 discount + $15 tax on the original $100).
if (reward.IsValid)
{
var discount = reward.ToDiscountModel(ExtendedPriceTotal);
Discounts.Add(discount);
DiscountAmount = discount.Amount;
}
}
I guess this is a common practice in some markets. But as this is for a B2C solution in Sweden. An advertised discount of 200 SEK on a 800 SEK cart should render a customer facing total price of 600 SEK including taxes.
This is an img of my promotion in the Marketing Module
This gives me the following on the Cart JSON
Cart
subTotal: 640
subTotalWithTax: 800
discountAmount: 160
discountTotal: 160
discountTotalWithTax: 160
subTotalDiscount: 0
subTotalDiscountWithTax:0
discountTotalWithTax: 160
taxTotal: 160
total: 640
totalWithTax: 800 (Calculated. Not in standard JSON response)
So either I've miss configured the promotion or my implementation of the storefront code for promotions is lacking in some way.
Currently, VC implement only the one discount to the order subtotal policy:
When a discount is applied to the cart subtotal, the tax calculation
has already been applied, and is reflected in the tax subtotal.
Therefore, a discount applying to the cart subtotal will occur after
tax. For instance, if the cart subtotal is $100, and $15 is the tax
subtotal, a cart-wide discount of 10% will yield a total of $105 ($100
subtotal – $10 discount + $15 tax on the original $100).
But we are working on change the totals calculation to make this process more flexible and extensible for supporting any calculation policies.
You can achieve what you want by a little customization within your extension module:
Extend ShopingCart class with following code
public class ShopingCart2: ShoppingCart
{
public decimal DiscountAmountWithTax
{
get
{
return DiscountAmount + DiscountAmount * TaxPercentRate;
}
}
public override decimal TaxTotal
{
get
{
var result = base.TaxTotal;
result -= DiscountAmountWithTax - DiscountAmount;
return result;
}
}
public override decimal DiscountTotalWithTax
{
get
{
var result = base.DiscountTotalWithTax;
result += DiscountAmountWithTax - DiscountAmount;
return result;
}
}
}
Extend domain CustomerOrder type with the same code as for ShoppingCart above
Register your ShoopingCart2 and CustomerOrder2 in AbstractTypeFactory
AbstractTypeFactory<ShoppingCart>.OverrideType<ShoppingCart, ShoppingCart2>();
AbstractTypeFactory<CustomerOrder>.OverrideType<CustomerOrder, CustomerOrder2>();
Update your storefront to latest version from dev (this commit required for normal work https://github.com/VirtoCommerce/vc-storefront/commit/2464548c171c811a9d63edba0bdf6af93e8c902b)
Modify ShopingCart class in your storefront - add same changes as you made in your new ShoppingCart2 type earlier.
Get the desired behavior

openerp 7: displaying Manufacturing Orders for Sales Order

I have created a custom entity that lets us select a sales order. The desire is that when a sales order is selected, it should show a list of manufacturing orders linked to that sales order.
How to go about getting this in place? And what should be in the mode? fields.related or fields.one2many?
Thanks
code:
class my_custom(osv.osv):
_name = 'mrp.mycustom'
_columns={
'name': fields.char('Name',size=64),
'salesorder_id': fields.many2one('sale.order','Sales Order')
}
my_custom()
There is no direct link between sale order and manufacturing order. You need to add a link first.then you you can use a one2many to show your manufacturing order