Skip to content

Commit

Permalink
initial commit tax-rebase plugin
Browse files Browse the repository at this point in the history
Initial commit for issue #972
  • Loading branch information
aaronjudd committed Aug 3, 2016
1 parent 2f4a0a6 commit 9a0614f
Show file tree
Hide file tree
Showing 37 changed files with 1,216 additions and 49 deletions.
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ raix:ui-dropped-event
risul:moment-timezone
tmeasday:publish-counts
vsivsi:job-collection
react-meteor-data

# Testing packages
dburles:factory
Expand Down
2 changes: 2 additions & 0 deletions .meteor/versions
Empty file.
Empty file.
13 changes: 13 additions & 0 deletions imports/plugins/core/tax-base/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import "./checkout/taxes.html";
import "./checkout/taxes.js";
import "./settings/griddle.jsx";
import "./settings/avalara.html";
import "./settings/avalara.js";
import "./settings/custom.html";
import "./settings/custom.js";
import "./settings/settings.html";
import "./settings/settings.js";
import "./settings/taxcloud.html";
import "./settings/taxcloud.js";
import "./settings/taxjar.html";
import "./settings/taxjar.js";
8 changes: 8 additions & 0 deletions imports/plugins/core/tax-base/client/settings/avalara.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template name="avalaraSettings">
{{#autoForm collection=Collections.Packages schema=packageConfigSchema doc=packageData type="update" id="avalara-update-form"}}
<div class="panel-body">
{{>afQuickField name='settings.avalara.apiLoginId' class='form-control'}}
</div>
{{> shopSettingsSubmitButton}}
{{/autoForm}}
</template>
31 changes: 31 additions & 0 deletions imports/plugins/core/tax-base/client/settings/avalara.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Template } from "meteor/templating";
import { AutoForm } from "meteor/aldeed:autoform";
import { i18next } from "/client/api";
import { Packages } from "/lib/collections";
import { TaxPackageConfig } from "../../lib/collections/schemas";

Template.avalaraSettings.helpers({
packageConfigSchema() {
return TaxPackageConfig;
},
packageData() {
return Packages.findOne({
name: "reaction-taxes"
});
}
});


AutoForm.hooks({
"avalara-update-form": {
onSuccess: function () {
return Alerts.toast(i18next.t("shopSettings.shopTaxMethodsSaved"),
"success");
},
onError: function (operation, error) {
return Alerts.toast(
`${i18next.t("shopSettings.shopTaxMethodsFailed")} ${error}`, "error"
);
}
}
});
52 changes: 52 additions & 0 deletions imports/plugins/core/tax-base/client/settings/custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template name="customTaxRates">
<div>
{{> React component=griddleTable
publication="Taxes"
collection=Taxes
matchingResultsCount="taxes-count"
filteredFields=filteredFields
columns=filteredFields
noDataMessage=noDataMessage
onRowClick=editRow
useExternal=true
}}
</div>


{{instance}}
{{#if instance.state.get 'editing'}}
<div>
{{#autoForm
collection=Collections.Taxes
schema=Schemas.Taxes
type="method"
meteormethod="taxes/addRate"
id="customTaxRates-update-form"
}}
{{> afQuickField name='taxCode' options=taxCodes class='form-control'}}
{{> afQuickField name='cartMethod' options="allowed" class='form-control'}}
{{> afQuickField name='taxLocale' options="allowed" class='form-control'}}
{{> afQuickField name='taxShipping'}}
{{> afQuickField name='taxIncluded'}}
{{> afQuickField name='discountsIncluded'}}
{{> afQuickField name='country' options=countryOptions value=country class='form-control'}}
<div>
<label class="control-label">{{afFieldLabelText name='region'}}</label>
{{#if statesForCountry}}
{{>afFieldInput name="region" value=region options=statesForCountry class='form-control'}}
{{else}}
{{>afFieldInput name="region" value=region class='form-control'}}
{{/if}}
{{#if afFieldIsInvalid name="region"}}
<span class="help-block">{{afFieldMessage name="region"}}</span>
{{/if}}
</div>
{{> afQuickField name='postal' class='form-control'}}
{{> afQuickField name='rate' class='form-control'}}
{{> shopSettingsSubmitButton}}
{{/autoForm}}
</div>
{{else}}
<div class="nav-group">...</div>
{{/if}}
</template>
116 changes: 116 additions & 0 deletions imports/plugins/core/tax-base/client/settings/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// import { checkNpmVersions } from "meteor/tmeasday:check-npm-versions";
import { Template } from "meteor/templating";
import { MeteorGriddle } from "./griddle";
import { ReactiveDict } from "meteor/reactive-dict";
import { Shops, Countries } from "/lib/collections";
import { Taxes, TaxCodes } from "../../lib/collections";
import { i18next } from "/client/api";
import { TaxPackageConfig } from "../../lib/collections/schemas";

Template.customTaxRates.onCreated(function () {
this.autorun(() => {
this.subscribe("Taxes");
});

this.state = new ReactiveDict();
this.state.setDefault({
editing: false
});
});

Template.customTaxRates.helpers({
packageConfigSchema() {
return TaxPackageConfig;
},
countryOptions: function () {
return Countries.find().fetch();
},
country: function () {
const shop = Shops.findOne();
if (shop && typeof shop.addressBook === "Array") {
const country = shop.addressBook[0].country;
return country;
}
return [];
},
statesForCountry: function () {
const shop = Shops.findOne();
const selectedCountry = AutoForm.getFieldValue("country");
if (!selectedCountry) {
return false;
}
if ((shop !== null ? shop.locales.countries[selectedCountry].states : void 0) === null) {
return false;
}
options = [];
if (shop && typeof shop.locales.countries[selectedCountry].states === "object") {
for (const state in shop.locales.countries[selectedCountry].states) {
if ({}.hasOwnProperty.call(shop.locales.countries[selectedCountry].states, state)) {
const locale = shop.locales.countries[selectedCountry].states[state];
options.push({
label: locale.name,
value: state
});
}
}
}
return options;
},
filteredFields() {
return ["taxCode", "rate", "country", "region", "postal"];
},
Taxes() {
return Taxes;
},
packageData() {
return Taxes.find();
},
taxCodes() {
const instance = Template.instance();
if (instance.subscriptionsReady()) {
const taxCodes = TaxCodes.find().fetch();
const options = [{
label: i18next.t("app.auto"),
value: "none"
}];

for (let taxCode of taxCodes) {
options.push({
label: i18next.t(taxCode.label),
value: taxCode.id
});
}
return options;
}
return [];
},
griddleTable() {
return MeteorGriddle;
},
editRow(options) {
return (options ) => {
const instance = Template.instance();
console.log(instance.state.get("editing"));
instance.state.set("editing", options.props.data);
Session.set("editingTaxCode", options.props.data);
console.log("here in edit row", options.props.data);
};
},
noDataMessage() {
return i18next.t("shopSettings.noCustomTaxRatesFound");
}
});

AutoForm.hooks({
"customTaxRates-update-form": {
onSuccess: function () {
return Alerts.toast(i18next.t("shopSettings.shopCustomTaxRatesSaved"),
"success");
},
onError: function (operation, error) {
return Alerts.toast(
`${i18next.t("shopSettings.shopCustomTaxRatesFailed")} ${error}`, "error"
);
}
}
});
Loading

0 comments on commit 9a0614f

Please sign in to comment.