I have stored values from a html-form to localstorage and when I get the data back from localstorage to form for editing, data will come to input-text fields like it should, but not to dropdown or checkbox fields.
What do I need to do to get values also in dropdowns or checkbox fields? Checkbox has multiple values saved as array so those needs to be separated.
if (localStorage.hasOwnProperty('key')) {
$(function editform() {
var lsdata = JSON.parse(localStorage.getItem('key'));
$('#formid').val(lsdata.FormID);
$('#createdate').val(lsdata.CreateDate);
$('#formfiller').val(lsdata.FormFiller);
$('#customerlist').val(lsdata.CustomerName); //dropdown
$('#contact').val(lsdata.CustomerContact);
$('#worklist').val(lsdata.WorkName); //dropdown
$('#readytodate').val(lsdata.ReadyToDate);
$('#instructions').val(lsdata.Instructions);
$('#amount').val(lsdata.Amount);
$('#amountpcs').val(lsdata.PcsAmount);
$('#chargefull').val(lsdata.ChargeFull);
$('#chargepcs').val(lsdata.ChargeByPcs);
$('#freightcost').val(lsdata.FreightCost);
$('#materiallist').val(lsdata.MaterialName); //checkbox with multiple options
// localstorage value
{
"$id": "1",
"Customer": null,
"Material": null,
"Status": null,
"Work": null,
"FormID": 150,
"CreateDate": "2019-09-17T00:00:00",
"FormFiller": "JOkuMuu",
"CustomerID": null,
"CustomerName": "Wsoy",
"CustomerContact": "Masa",
"WorkID": null,
"WorkName": "Lajitelmapakkaus",
"ReadyToDate": "2019-09-19T00:00:00",
"Instructions": "Tarkasta kirjat ",
"Amount": 50,
"PcsAmount": null,
"ChargeFull": null,
"ChargeByPcs": null,
"FreightCost": null,
"MaterialID": null,
"MaterialName": "Xpohja,Tarra",
"WorkHoursWR": null,
"WorkHoursIT": null,
"WorkHoursCS": null,
"StatusID": null
}
You use hasOwnProperty which is not a method specific to LocalStorage but Object. Instead, you should use setItem/getItem methods of LocalStorage
// localstorage value
var data = {
"$id": "1",
"Customer": null,
"Material": null,
"Status": null,
"Work": null,
"FormID": 150,
"CreateDate": "2019-09-17T00:00:00",
"FormFiller": "JOkuMuu",
"CustomerID": null,
"CustomerName": "Wsoy",
"CustomerContact": "Masa",
"WorkID": null,
"WorkName": "Lajitelmapakkaus",
"ReadyToDate": "2019-09-19T00:00:00",
"Instructions": "Tarkasta kirjat ",
"Amount": 50,
"PcsAmount": null,
"ChargeFull": null,
"ChargeByPcs": null,
"FreightCost": null,
"MaterialID": null,
"MaterialName": "Xpohja,Tarra",
"WorkHoursWR": null,
"WorkHoursIT": null,
"WorkHoursCS": null,
"StatusID": null
}
localStorage.setItem('key', JSON.stringify(data));
if (fetchedData = localStorage.getItem('key')) {
console.log('Item found!', fetchedData);
}else{
console.log('Item NOT found!');
}
Note that, this snippet won't work since same origin error will be thrown.
Hope this helps.
Related
hi im building application and i need to store data in txt file and retrieve it
the data is object like this .. .
[
{
"key": 0,
"id": 1,
"number": "1001",
"name": "سلعة ملموسة",
"offer_end_date": null,
"offer_start_date": null,
"components": [],
"quantity": "9",
"product": {
"id": 1,
"name": "سلعة ملموسة",
"number": "1001",
"product_id": null,
"foreign_name": "Product",
"can_be_sold": 1,
"can_be_purchased": 1,
"can_be_rented": 1,
"available_on_pos": 1,
"pos_quick_lunch": 1,
"available_on_manufacture": 1,
"product_category_id": 1,
"product_unit_type_id": null,
"location_id": null,
"area_id": null,
"discount_value": 10,
"balance": null,
"smallest_unit_id": 1,
"smallest_unit_barcode": null,
"smallest_unit_selling_price": 10,
"smallest_unit_cost": null,
"smallest_unit_selling_price_above": null,
"smallest_unit_selling_price_above_price": null,
"tax_value": 16,
"state_id": 1,
"warehouse_id": null,
"product_type_id": 1,
"product_policy_id": null,
"tax_user_id": null,
"user_id": null,
"get_specification_on_lines": null,
"is_products_has_expire_date": 1,
"is_products_has_patch_number": 1,
"is_products_has_serial_number": 1,
"offer_end_date": null,
"offer_start_date": null,
"last_purchase_date": null,
"last_purchase_purchase": null,
"last_purchase_price": null,
"last_purchase_discount": null,
"created_by": null,
"deleted_by": null,
"approved_by": null,
"approved_date": null,
"approved_state_id": null,
"note": null,
"created_at": "2022-03-04T06:52:16.000000Z",
"updated_at": "2022-03-04T06:52:16.000000Z",
"deleted_at": null,
"get_pos_product_componentss": [],
"get_pos_product_components": [],
"get_smallest_unit_id": {
"id": 1,
"name": "حبة",
"foreign_name": "unit",
"number": "1",
"created_by": 1,
"deleted_by": null,
"approved_by": null,
"approved_date": null,
"approved_state_id": null,
"note": null,
"created_at": "2022-03-04T06:52:15.000000Z",
"updated_at": "2022-03-04T06:52:15.000000Z",
"deleted_at": null
},
"get_product_offers": []
},
"smallest_unit_selling_price": 10,
"smallest_unit_selling_price_above": null,
"smallest_unit_selling_price_above_price": null,
"discount": 0,
"allowed_discount": 10,
"tax_value": 16,
"unit": "حبة",
"smallest_unit_id": 1,
"note": null,
"active": 1,
"price": 104.39999999999999
}
]
now this object i need to store it in file called text.txt
how can i store the object inside the file ..
and how can i retrieve the data using JavaScript ..
thanks ..
ive found solutions thats i can put the object in cookies but my problem with cookies they only allowing 4kb of data
never mind i found this solution ..
first of store data in localStorage like this ..
localStorage.setItem("orders", JSON.stringify(this.orders));
then access it like this ..
var orders = JSON.parse(localStorage.getItem('orders'));
console.log(orders);
I am using graphs, so whenever I choose to show data according to the months, I will have to show data for the each month, I have fields like totalAmount, paidAmount , I should sum data for that month.
const myArray = [
{
"id": 9,
"userId": null,
"invoiceNumber": "biscuitInvoice",
"billedBy": 1,
"billedTo": 2,
"addGst": false,
"invoiceDate": "2021-05-08T12:05:00",
"dueDate": "2021-05-21T12:03:00",
"totalAmount": 11.8,
"discountSymbol": null,
"discountPercent": null,
"subTotal": null,
"notes": null,
"signature": null,
"reachMail": "",
"reachPhoneNo": null,
"businessLogo": null,
"clientName": "Checking Business",
"businessName": "Chocolate Business",
"paymentAmount": 140,
"status": "Created",
"igst": 1.8,
"cgst": 0,
"amount": null,
"sgst": 0,
"businessClient": null,
"businessProfile": null,
"invoiceAttachments": [],
"invoiceItems": [],
"invoiceTerms": []
},
{
"id": 8,
"userId": null,
"invoiceNumber": "invq32",
"billedBy": 1,
"billedTo": 3,
"addGst": false,
"invoiceDate": "2021-04-04T10:10:22",
"dueDate": "2021-05-13T10:10:00",
"totalAmount": 354,
"discountSymbol": null,
"discountPercent": null,
"subTotal": null,
"notes": null,
"signature": null,
"reachMail": "",
"reachPhoneNo": null,
"businessLogo": null,
"clientName": "Checking",
"businessName": "Chocolate Business",
"paymentAmount": 120,
"status": "Paid",
"igst": 54,
"cgst": 0,
"amount": null,
"sgst": 0,
"businessClient": null,
"businessProfile": null,
"invoiceAttachments": [],
"invoiceItems": [],
"invoiceTerms": []
}
]
In that list, I have invoiceDate, one object is of april month and other is of May month.
Click here what I meant to do,I want this functionality
How can I do that, any help?
Here is the function you need:
function getDesiredMonth(data, month) {
return data.filter((item) => item.invoiceDate.split("-")[1] === month)
}
For example, you can call it like this to get May invoices:
getDesiredMonth(myArray, '05')
Let me know if that works for you :)
function filterDataByMonth(data, month){
return data.filter(i => new Date(i.invoiceDate).getMonth() + 1 === month);
}
Answering cause I dont have enough rep to comment.
I guess you can follow these steps:
Initialize aggregate variables that you need (basically sum of sgst or whatever) to 0.
Iterate over list
Use library such as luxon or moment to parse invoice date (they're in ISO, so it'll be straightforward)
Identify month number from parsed object.
Aggregate whatever data you need into the variables initiaziled earlier (eg. total_sgst += current_obj.sgst)
???
Profit?
Is it possible to get the Braintree fee amount while searching for transactions using Transaction.search() method? I specifically use
Braintree Node.js SDK API, so when I call the method:
const gateway = braintree.connect({
environment: braintree.Environment.Production,
merchantId : process.env.BRAINTREE_merchantId,
publicKey : process.env.BRAINTREE_publicKey,
privateKey : process.env.BRAINTREE_privateKey,
});
// start and end are well formatted dates, irrelevant here
const stream = gateway.transaction.search((search) => {
search.createdAt().between(start, end)
});
let result = [];
stream.on("data", (transaction) => {
result.push(transaction);
});
stream.on("end", () => {
console.log(result[0]);
});
stream.on("error", reject);
stream.resume();
My console.log(result[0]) shows pretty big (160 lines of code) single transaction object, where transaction.serviceFeeAmount: null.
console.log({
"id": "1egncjr5",
"status": "settled",
"type": "sale",
"currencyIsoCode": "EUR",
"amount": "799.00",
"merchantAccountId": "mycompanyEUR",
"subMerchantAccountId": null,
"masterMerchantAccountId": null,
"orderId": "54144",
"createdAt": "2018-03-07T08:55:09Z",
"updatedAt": "2018-03-07T19:41:10Z",
"customer": {
"id": null,
"firstName": null,
"lastName": null,
"company": "Kunlabora NV",
"email": "client#email.com",
"website": null,
"phone": null,
"fax": null
},
"billing": {
"id": null,
"firstName": null,
"lastName": null,
"company": "Kunlabora NV",
"streetAddress": "Veldkant 33 A",
"extendedAddress": null,
"locality": "Kontich",
"region": null,
"postalCode": "2550",
"countryName": "Belgium",
"countryCodeAlpha2": "BE",
"countryCodeAlpha3": "BEL",
"countryCodeNumeric": "056"
},
"refundId": null,
"refundIds": [],
"refundedTransactionId": null,
"partialSettlementTransactionIds": [],
"authorizedTransactionId": null,
"settlementBatchId": "2018-03-08_mycompanyEUR_ecwhvhcf",
"shipping": {
"id": null,
"firstName": null,
"lastName": null,
"company": null,
"streetAddress": null,
"extendedAddress": null,
"locality": null,
"region": null,
"postalCode": null,
"countryName": null,
"countryCodeAlpha2": null,
"countryCodeAlpha3": null,
"countryCodeNumeric": null
},
"customFields": "",
"avsErrorResponseCode": null,
"avsPostalCodeResponseCode": "U",
"avsStreetAddressResponseCode": "U",
"cvvResponseCode": "M",
"gatewayRejectionReason": null,
"processorAuthorizationCode": "735709",
"processorResponseCode": "1000",
"processorResponseText": "Approved",
"additionalProcessorResponse": null,
"voiceReferralNumber": "",
"purchaseOrderNumber": null,
"taxAmount": "0.00",
"taxExempt": false,
"creditCard": {
"token": null,
"bin": "CENSORED",
"last4": "CENSODER",
"cardType": "MasterCard",
"expirationMonth": "CENSORED",
"expirationYear": "CENSORED",
"customerLocation": "CENSORED",
"cardholderName": "",
"imageUrl": "https://assets.braintreegateway.com/payment_method_logo/mastercard.png?environment=production",
"prepaid": "No",
"healthcare": "No",
"debit": "No",
"durbinRegulated": "No",
"commercial": "No",
"payroll": "No",
"issuingBank": "BNP PARIBAS FORTIS",
"countryOfIssuance": "BEL",
"productId": "MCB",
"uniqueNumberIdentifier": null,
"venmoSdk": false,
"maskedNumber": "CENSORED",
"expirationDate": "04/2020"
},
"statusHistory": [
{
"timestamp": "2018-03-07T08:55:10Z",
"status": "authorized",
"amount": "799.00",
"user": "office#mycompany.com",
"transactionSource": "api"
},
{
"timestamp": "2018-03-07T08:55:10Z",
"status": "submitted_for_settlement",
"amount": "799.00",
"user": "office#mycompany.com",
"transactionSource": "api"
},
{
"timestamp": "2018-03-07T19:41:10Z",
"status": "settled",
"amount": "799.00",
"user": null,
"transactionSource": ""
}
],
"planId": null,
"subscriptionId": null,
"subscription": {
"billingPeriodEndDate": null,
"billingPeriodStartDate": null
},
"addOns": [],
"discounts": [],
"descriptor": {
"name": null,
"phone": null,
"url": null
},
"recurring": false,
"channel": "woocommerce_bt",
"serviceFeeAmount": null,
"escrowStatus": null,
"disbursementDetails": {
"disbursementDate": null,
"settlementAmount": null,
"settlementCurrencyIsoCode": null,
"settlementCurrencyExchangeRate": null,
"fundsHeld": null,
"success": null
},
"disputes": [],
"authorizationAdjustments": [],
"paymentInstrumentType": "credit_card",
"processorSettlementResponseCode": "",
"processorSettlementResponseText": "",
"threeDSecureInfo": null,
"shipsFromPostalCode": null,
"shippingAmount": null,
"discountAmount": null,
"paypalAccount": {},
"coinbaseAccount": {},
"applePayCard": {},
"androidPayCard": {},
"visaCheckoutCard": {},
"masterpassCard": {}
})
Question: How do I get the transaction fee here?
You might find it in transactionFeeAmount field
This is the answer I received from Braintree support team:
Unfortunately no it is not possible to search for the Braintree fee amount using the API at this time (meaning 14/05/2018).
You can calculate the fees for individual transactions by performing an Advanced Transaction Search.
Log into the Control Panel
Under Advanced Search, click Transactions
Uncheck the box next to Creation date range
Check the box next to Disbursed date range
Choose your desired date range
Click Search
On the results page, click Download
Open the CSV file in the spreadsheet program of your choice
From here, you can create additional columns for your transaction fees. To find your specific transaction fees, look at the Pricing Schedule on your statement. Make sure to round down, and then apply the fees to your individual transactions.
So it looks like I am going to implement some PhantomJS module to do just that.
I want to display client id and country based on user selecting client from client list,I can be display entire selected object but can not display selected client details.
<label class="control-label red">Client</label>
{{selectedClient}}
<select class="form-control" ng-model="selectedClient">
<option ng-repeat="client in clients" value="{{client.id}}">{{client.name}}</option>
</select>
<a href="javascript:void(0)" data-toggle="modal" data-target="#addressModel"><i class="fa fa-map-marker"></i>
{{selectedClient.id}},{{selectedClient.address_info.country}}
</a>
Here selectedClient is displaying accordingly selecting from select-box,but selectedClient.id and selectedClient.address_info.country is not displaying even though they holding some values.
output of selectedClient is,
{
"id": 127,
"payment_terms_id": null,
"name": "Shihabs company",
"note": null,
"created_by": 0,
"updated_by": null,
"deleted_by": null,
"created_at": "2015-03-09 10:32:31",
"updated_at": "2015-03-09 10:32:31",
"deleted_at": null,
"status": 1,
"payment_term": null,
"address_info": {
"id": 54,
"client_id": 127,
"street": null,
"city": null,
"pobox": null,
"country": null,
"phone": null,
"work_phone": null,
"mobile": null,
"email": null,
"website": null,
"billing_street": null,
"billing_city": null,
"billing_pobox": null,
"billing_country": null,
"billing_phone": null,
"billing_work_phone": null,
"billing_mobile": null,
"billing_email": null,
"shipping_street": null,
"shipping_city": null,
"shipping_pobox": null,
"shipping_country": null,
"shipping_phone": null,
"shipping_work_phone": null,
"shipping_mobile": null,
"shipping_email": null,
"created_by": null,
"updated_by": null,
"deleted_by": null,
"created_at": "2015-03-09 10:32:31",
"updated_at": "2015-03-09 10:32:31",
"deleted_at": null,
"status": 1
}
}
try this way to bind select option
<select ng-model="selectedClient" ng-options="client.name for client in
clients"></select>
I am sending a JSON object in order to initialize some input and select values on my page. The object holds a ShipTo property. and I want the dropdown to be populated with this initial value. For some reason it is not populating, even though they are the same object. I even added in a track by to make sure it is testing equality based on the CompanyName (not exactly sure if thats what track by is meant for) Here is what I have:
the JSON Object:
{
"AccountNumber": "12345",
"Email": null,
"CompanyName": "HK Electric",
"Inactive": false,
"PhoneNumbers": null,
"ChildOfCustomer": "00000000-0000-0000-0000-000000000000",
"Id": "a4aab309-321c-4b09-969c-073eb83b90ad",
"ModifiedBy": null,
"ModifiedOn": "2014-07-16T18:46:52.065Z",
"CreatedBy": null,
"CreatedOn": "2014-07-16T18:46:52.065Z",
"IsDeleted": false
}
vm.shiptos :
[
{
"ShipTo": {
"AccountNumber": "1234",
"Email": null,
"CompanyName": "Mk Mechanical",
"Inactive": false,
"PhoneNumbers": null,
"ChildOfCustomer": "00000000-0000-0000-0000-000000000000",
"Id": "b90f9b8c-3910-43ec-8c14-6294155ce855",
"ModifiedBy": null,
"ModifiedOn": "2014-07-15T23:03:58.47Z",
"CreatedBy": null,
"CreatedOn": "2014-07-15T23:03:58.47Z",
"IsDeleted": false
},
"Addresses": [],
"Customer": null,
"Job": null,
"Orders": []
},
{
"ShipTo": {
"AccountNumber": "12345",
"Email": null,
"CompanyName": "HK Electric",
"Inactive": false,
"PhoneNumbers": null,
"ChildOfCustomer": "00000000-0000-0000-0000-000000000000",
"Id": "a4aab309-321c-4b09-969c-073eb83b90ad",
"ModifiedBy": null,
"ModifiedOn": "2014-07-16T18:46:52.065Z",
"CreatedBy": null,
"CreatedOn": "2014-07-16T18:46:52.065Z",
"IsDeleted": false
},
"Addresses": [],
"Customer": null,
"Job": null,
"Orders": []
}
]
The ngoptions statement in my HTML:
<select id="ddlShipto" name="ddlShipto" data-ng-model="vm.Shipto" data-ng-options="shipto as shipto.ShipTo.CompanyName for shipto in vm.shiptos track by shipto.ShipTo.CompanyName" class="form-control FloatLeft" required>
<option selected="selected" value="">--Select One--</option>
</select>
Not sure track by is not what you're looking for here.
This is the ng-options syntax you are using: select as label for value in array
The part you have wrong is the select parameter. This parameter's expression gets equality checked against the model to determine if it is a match (and will automatically set selected option, etc). So, right now your select parameter is shipto. This means that in order to default to a value, your model needs to be equal to the object in vm.shiptos.
Here's two options:
The first option is to loop through the vm.shiptos and set your model to the one you would like to default. eg:
angular.forEach($scope.vm.shiptos,function(el,i){
//check objects against the JSON object and set the model to the object if desired
if (el.ShipTo.AccountNumber === jsonObject.AccountNumber){
theModelForNgOptions = el;
}
};
The second option you have is to change the ng-options select parameter to something else on the object, so that the model doesn't have to be the whole object. If AccountNumber is your unique identifier to those objects, you could change your options to:
data-ng-options="shipto.ShipTo.AccountNumber as shipto.ShipTo.CompanyName for shipto in vm.shiptos
Now, the select will default only if the attached model is equal to shipto.AccountNumber. Here is an example jsfiddle of this at work: http://jsfiddle.net/ADukg/5392/