How to set an option value in symfony2 entity - symfony-2.1

I'm picking information from the database in to a dropdown
and here it
-------------------
id | username
-------------------
10 | llj
12 | AFS
How can I obtain this:
<option value="10">llj</option>
<option value="12">AFS</option>
in symfony2
->add('supervisor','entity', array(
'class' => 'AdminBundle:supervisor',
'expanded' => false,
'multiple' => false,
'placeholder'=>'',
'empty_value' => null
))

Related

[Shopware6]: How to reuse the customer selection component in administration?

I'm trying to create a custom-field that is an entity-single-select for customers, exactly like the one in the sw-order module as seen here
sw-order-create-details-header > sw-entity-single-select
Is there some way for me, to configure the look of my custom-field to be the same as the extended select-field in the sw-order module?
With that i mean, inclusive of firstName, lastName, address and customernumber?
(Without creating a a new component)
What i have so far is this:
protected $customFields = [
[
'name' => 'referrer_set',
'config' => [
'label' => [
'en-GB' => 'Referrer',
'de-DE' => 'Referrer',
],
],
'customFields' => [
[
'active' => true,
'name' => 'refferer_set',
'type' => CustomFieldTypes::ENTITY,
'config' => [
'componentName' => 'sw-entity-single-select',
'entity' => CustomerDefinition::ENTITY_NAME,
'placeholder' => "Wurde empfohlen von ...",
'highlightSearchTerm' => true,
'allowEntityCreation' => false,
'show-clearable-button' => true,
'labelProperty' => 'firstName',
'label' => [
'en-GB' => 'Empfohlen von',
'de-DE' => 'Empfohlen von',
],
],
],
],
'relations' => [
[
'entityName' => CustomerDefinition::ENTITY_NAME,
],
],
],
];
Unfortunately this isn't quite so trivial to achieve.
You could override the component which is responsible for rendering custom fields sw-form-field-renderer.
Inside the override you check if it is your specific custom field that should be rendered. In the template of the override you then set the content of the slot result-item, which is a corresponding to each option in the dropdown. You'll additionally have to extend the binds of the component with a criteria to add the billing address of the customer as an association.
The override:
import template from './sw-form-field-renderer.html.twig';
const { Component } = Shopware;
const { Criteria } = Shopware.Data;
Component.override('sw-form-field-renderer', {
template,
computed: {
isMyCustomField() {
return this.config.componentName === 'sw-entity-single-select' && this.$attrs.name === 'refferer_set';
},
bind() {
const bind = this.$super('bind');
if (this.isMyCustomField) {
const criteria = new Criteria;
criteria.addAssociation('defaultBillingAddress.country');
bind.criteria = criteria;
}
return bind;
},
},
});
The template sw-form-field-renderer.html.twig:
{% block sw_form_field_renderer_scope_slots %}
{% parent %}
<template
v-if="isMyCustomField"
#result-item="{ item, index, labelProperty, searchTerm, highlightSearchTerm, isSelected, setValue, getKey }"
>
<!-- copy/paste from sw-order-create-details-header -->
<li
is="sw-select-result"
:selected="isSelected(item)"
v-bind="{ item, index }"
class="sw-order-create-details-header__customer-result"
#item-select="setValue"
>
<div class="sw-order-create-details-header__customer-result-item has-many-childrens">
<div>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'firstName') || getKey(item, `translated.firstName`)"
:search-term="searchTerm"
/>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'lastName') || getKey(item, `translated.lastName`)"
:search-term="searchTerm"
/>
</div>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'customerNumber') || getKey(item, `translated.customerNumber`)"
:search-term="searchTerm"
class="text-truncate"
/>
</div>
<div
v-if="getKey(item, 'company') || getKey(item, `translated.company`)"
class="sw-order-create-details-header__customer-result-item"
>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'company') || getKey(item, `translated.company`)"
:search-term="searchTerm"
/>
</div>
<div class="sw-order-create-details-header__customer-result-item text-gray-500">
{{ item.defaultBillingAddress.street }} <br>
{{ item.defaultBillingAddress.zipcode }} {{ item.defaultBillingAddress.city }} <br>
{{ item.defaultBillingAddress.country.name }}
</div>
</li>
</template>
{% endblock %}

Using Stripe Upcoming Invoice to preview changes in subscription

I want to use Stripe Upcoming Invoices to display how much a user will be billed when he makes changes to his subscriptions. But it seems that I miss something...
Why do I get 29 instead of 0?
dump($plans['basic_monthly']->price);
29.0
dump($plans['premium_monthly']->price);
49.0
$stripe_customer = step1_create_customer();
$stripe_subscription = step2_create_subscription($stripe_customer, $plans['basic_monthly']->stripe_price_id);
dump([
'reason' => 'Nohting was changed (price_id and quantity are the same), so 0 is expected. Why 29 is here?',
'expected' => 0,
'actual' => upcoming($stripe_subscription, $plans['basic_monthly']->stripe_price_id)->amount_due/100,
]);
array:3 [▼
"reason" => "Nohting was changed (price_id and quantity are the same), so 0 is expected. Why 29 is here?"
"expected" => 0
"actual" => 29
]
dump([
'reason' => 'Transition to more expensive plan was made. 49 - 29 = 20 is expected',
'expected' => 20,
'actual' => upcoming($stripe_subscription, $plans['premium_monthly']->stripe_price_id)->amount_due/100,
]);
array:3 [▼
"reason" => "Transition to more expensive plan was made. 49 - 29 = 20 is expected"
"expected" => 20
"actual" => 20
]
function step1_create_customer()
{
$stripe = new \Stripe\StripeClient(env('STRIPE_SECRET_KEY'));
$test_clock = $stripe->testHelpers->testClocks->create([
'frozen_time' => time(),
'name' => sprintf('Testing Upcoming Invoices'),
]);
$stripe_customer = $stripe->customers->create([
'test_clock' => $test_clock->id,
'payment_method' => 'pm_card_visa',
'invoice_settings' => ['default_payment_method' => 'pm_card_visa'],
'metadata' => [
'testing_upcoming_invoices' => 1,
],
'expand' => [
'test_clock',
'invoice_settings.default_payment_method',
],
]);
return $stripe_customer;
}
function step2_create_subscription($stripe_customer, $stripe_price_id)
{
$stripe = new \Stripe\StripeClient(env('STRIPE_SECRET_KEY'));
$stripe_subscription = $stripe->subscriptions->create([
'customer' => $stripe_customer->id,
'items' => [
[
'price' => $stripe_price_id,
'quantity' => 1,
],
],
'metadata' => [
'testing_upcoming_invoices' => 1,
],
]);
return $stripe_subscription;
}
function upcoming($stripe_subscription, $stripe_price_id)
{
$stripe = new \Stripe\StripeClient(env('STRIPE_SECRET_KEY'));
$stripe_invoice = $stripe->invoices->upcoming([
'subscription' => $stripe_subscription->id,
'subscription_items' => [
[
'id' => $stripe_subscription->items->data[0]->id,
'price' => $stripe_price_id,
'quantity' => 1,
],
],
'subscription_cancel_at_period_end' => false,
'subscription_proration_behavior' => 'always_invoice',
//'subscription_proration_date' => $now,
]);
return $stripe_invoice;
}
What your code is doing here is upgrading a Subscription from Price A ($29/month) to Price B ($49/month) immediately after creation. You're also passing subscription_proration_behavior: 'always_invoice'.
When you upgrade or downgrade a subscription, Stripe calculates the proration for you automatically. This is something Stripe documents in details here and here.
In a nutshell, since you move from $29/month to $49/month immediately after creation, what happens is that Stripe calculates that:
You owe your customer credit for the time they paid on $29/month that they won't use. Since it's immediately after creation, you owe them $29.
The customer owes you for the remaining time for the new Price. Since it's the start of the month they owe you the full price of $49.
In a default integration, the proration is created as 2 separate InvoiceItems that are pending until the next cycle. In your case you pass proration_behavior: 'always_invoice' so an Invoice is created immediately with only those 2 line items. -$29 + $49 = $20 which is where the amount comes from.

Validation with Sequelize IsIn is not allowing only values in Array

I have a ReactJS Frontend that takes the value of a select and sends it to the backend to be saved to the database. But I want only allowed options to be saved. I am using ORM Sequelize.
Note: Data is arriving correctly in the backend, but even disallowed values are being saved to the database.
Node version: v10.16.2
Sequelize version: 5.19.0
purchase_unit: {
type: DataTypes.STRING,
allowNull: false,
validade: {
notNull: {
msg: 'The field "purchase unit" must be entered'
},
notEmpty: {
msg: 'The field "purchase unit" cannot be empty'
},
isIn: {
args: [["Und", "Pct"]],
msg: 'Entry not allowed for field "purchase unit"'
}
}
}
<select
value={productPurchaseUnit}
onChange={e => setProductPurchaseUnit(e.target.value)}
>
<option value="Und">Und</option>
<option value="Pct">Pct</option>
<option value="m2">m²</option>
<option value="g">g</option>
<option value="Kg">Kg</option>
<option value="Cm">Cm</option>
<option value="Mt">Mt</option>
</select>
According to official documentation The isIn option should be used as follows:
isIn: {
args: [['en', 'zh']],
msg: "Must be English or Chinese"
}

how to handle this kind of data

I'm using laravel-5.4 in this project
with "maatwebsite/excel"
I'm planning to create a feature for my website where the I can upload an excel file then show the data of this file in my view
the form I used to upload and send my data to the back end
public function bundleaddstudent(Request $request)
{
if($request->hasFile('excelstudent')){
$File = $request->file('excelstudent');
$path = $File->getRealPath();
$data = Excel::load($path, function($reader) {
})->toObject();
return view('User.content.tobe_added_students')
->with('selection', $this->selection())
->with('Students', $data);
}
else
{
return view('User.content.Add_student')
->with('selection', $this->selection())
->with('Students', 'No Data')
->with('request', $request);
}
}
now that the file that has been uploaded and has been handled in my controller for it to be converted as data object and was also been passed with the new view.
I now need to handle the passed data in my view this is how I've done it
#isset($Students)
#foreach ($Students as $key => $value)
<tr>
<td> {{$value}}</td>
</tr>
#endforeach
#endisset
but sadly the output of this is like this
if I try to {{ $value->dump() }}
an error would occur saying Method dump does not exist.
if I try to {{ $key }}
the output is an integer starting for 0 - 4 outputting it like
----------------------------
| studentID | Firstname |
----------------------------
| 1 | |
| 2 | |
| 3 | |
| 4 | |
you get the Idea
I also tried {{ $value->studentId }} but it is showing me nothing
base on the Comment of #LrdArc that I should Try
#isset( $Students )
{{ dd( $Students ) }}
#endisset
OUTPUT:
LaravelExcelReader {#353 ▼
+excel: PHPExcel {#361 ▶}
+reader: PHPExcel_Reader_Excel2007 {#354 ▶}
+file: "/tmp/phpu3zVBH"
+columns: []
+title: "phpu3zVBH"
+ext: ""
+encoding: false
+format: "Excel2007"
+parsed: RowCollection {#430 ▼
#title: "Sheet1"
#items: array:5 [▼
0 => CellCollection {#495 ▼
#title: null
#items: array:9 [▼
"studentid" => "15-2000332"
"firstname" => "Dummy1"
"lastname" => "Dummy1"
"middlename" => "Dummy1"
"course" => "Dummy1"
"ay" => "Dummy1"
"gender" => "Dummy1"
"address" => "Dummy1"
"contact" => "Dummy1"
]
}
1 => CellCollection {#496 ▼
#title: null
#items: array:9 [▼
"studentid" => "15-2000333"
"firstname" => "Dummy2"
"lastname" => "Dummy2"
"middlename" => "Dummy2"
"course" => "Dummy2"
"ay" => "Dummy2"
"gender" => "Dummy2"
"address" => "Dummy2"
"contact" => "Dummy2"
]
}
2 => CellCollection {#515 ▶}
3 => CellCollection {#514 ▶}
4 => CellCollection {#513 ▶}
]
}
Edit:
okay I've just tested it. Change toObject() into get() in your controller.
It's an object. Try something like this in your view:
#isset( $Students )
#foreach ( $Students as $student )
<tr>
<td>{{ $student->studentID }}</td>
<td>{{ $student->firstname }}</td>
<td>{{ $student->lastname }}</td>
<td>{{ $student->middlename }}</td>
</tr>
#endforeach
#endisset

Docusign API - prefilling tab values on envelope created from template

I was able to successfully generate and send an envelope from template using the Docusign API. The only problem is that the tab values and not pre-populating as expected (they remain blank). Here is the relevant code based on DocuSign-REST-API-Webinar-April2013:
/////////////////////////////////////////////
// STEP 2 - Create an envelope
////////////////////////////////////////////
$data = array(
"accountId" => $accountId,
"emailSubject" => "DocuSign API - Signature Request from Template",
"templateId" => $templateId,
"templateRoles" => array(
array(
"email" => $email,
"name" => $recipientName,
"inPersonSignerName" => "Some Customer",
"roleName" => "Customer",
"routingOrder" => 2,
"tabs" => array(
"textTabs" => array(
array(
"tabLabel"=> "mmr",
"value" => "29.95"
)
)
)
),
array(
"email" => $email,
"name" => $recipientName,
"inPersonSignerName" => "Some Tech",
"roleName" => "Tech",
"routingOrder" => 1,
"tabs" => array(
"textTabs" => array (
array (
"tabLabel" => "\\*state",
"value" => "North Carolina"),
array (
"tabLabel" => "\\*city",
"value" => "Raleigh")
)
)
)
),
"status" => "sent");
All my searches for answers on support forums, documentation, etc seem to point to what I have. I have double-checked the tabLabels and they are correct and assigned to the correct role. The template contains three roles - Tech (Sign In Person), Customer (Sign In Person), Data Entry (Receive a Copy).
Can anybody spot the problem? I also tried with just "tabLabel" => "state" and "tabLabel" => "city" (i.e. without the wildcard) but same problem. Let me know if you need more info. Thanks!
Have you verified in the template that the tags are assigned to the expected recipient? Based on your code above, it looks like the tag labeled "mmr" should be assigned to the Customer role and the tags labeled "state" and "city" are assigned to the Tech. Is that correct?

Resources