summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/pikul_cost.tag20
-rw-r--r--config/pikul_order.tag69
2 files changed, 83 insertions, 6 deletions
diff --git a/config/pikul_cost.tag b/config/pikul_cost.tag
index bc0444f..f885c12 100644
--- a/config/pikul_cost.tag
+++ b/config/pikul_cost.tag
@@ -1,26 +1,34 @@
-UserTag pikul_cost Order company origin district city province weight service
+UserTag pikul_cost Order company service district city province weight
UserTag pikul_cost Routine <<EOR
sub {
- my ($company, $origin, $district, $city, $province, $weight, $service) = @_;
- my (@provisions, $table);
+ my ($company, $service, $district, $city, $province, $weight) = @_;
+ my (@provisions, $origin, $table);
if ($company == $::Variable->{PIKUL_ANTERAJA}) {
@provisions = (
"$Global::Variable->{ANTERAJA_BASE_PATH}",
"$Global::Variable->{ANTERAJA_ACCESS_KEY_ID}",
"$Global::Variable->{ANTERAJA_SECRET_ACCESS_KEY}"
);
+ $origin = $::Variable->{ANTERAJA_ORIGIN};
$table = 'anteraja';
} elsif ($company == $::Variable->{PIKUL_SICEPAT}) {
@provisions = (
"$Global::Variable->{SICEPAT_API_KEY}"
);
+ $origin = $::Variable->{SICEPAT_ORIGIN};
$table = 'sicepat_destination';
}
use Pikul;
Pikul::init($company, \@provisions);
- my $cost = Pikul::cost($origin, $Tag->query({sql => "SELECT code FROM $table WHERE \
- district='$district' AND city='$city' AND province='$province'",
- wantarray => 1})->[0]->[0] || '', $weight, $service);
+ my $cost = Pikul::cost(
+ $origin,
+ $Tag->query({
+ sql => "SELECT code FROM $table WHERE district='$district' AND \
+ city='$city' AND province='$province'",
+ wantarray => 1
+ })->[0]->[0] || '',
+ $weight,
+ $service);
Pikul::cleanup();
return $cost;
}
diff --git a/config/pikul_order.tag b/config/pikul_order.tag
new file mode 100644
index 0000000..8e955ad
--- /dev/null
+++ b/config/pikul_order.tag
@@ -0,0 +1,69 @@
+UserTag pikul_order Order order_number
+UserTag pikul_order Routine <<EOR
+sub {
+ my $order_number = shift;
+ my ($shipmode, $nitems, $subtotal, $fname, $lname, $address1, $address2, $city, $state, $zip,
+ $phone_day)
+ = @{$Tag->query({
+ sql => "SELECT shipmode,nitems,subtotal,fname,lname,address1,address2,city,state,zip,\
+ phone_day FROM transactions WHERE code='$order_number'",
+ wantarray => 1
+ })->[0]};
+ my @parts = split(/ /, $shipmode, 2);
+ my ($table, $service) = split(/_/, shift @parts);
+ my ($company, @provisions, $origin);
+ if (substr($table, 0, 8) eq 'anteraja') {
+ $company = $::Variable->{PIKUL_ANTERAJA};
+ @provisions = (
+ "$Global::Variable->{ANTERAJA_BASE_PATH}",
+ "$Global::Variable->{ANTERAJA_ACCESS_KEY_ID}",
+ "$Global::Variable->{ANTERAJA_SECRET_ACCESS_KEY}",
+ "$Global::Variable->{ANTERAJA_PREFIX}"
+ );
+ $origin = "$::Variable->{ANTERAJA_ORIGIN}";
+ } elsif (substr($table, 0, 7) eq 'sicepat') {
+ $company = $::Variable->{PIKUL_SICEPAT};
+ @provisions = (
+ "$Global::Variable->{SICEPAT_API_KEY}"
+ );
+ $origin = "$::Variable->{SICEPAT_ORIGIN}";
+ $table .= '_destination';
+ }
+ my @items = @{$Tag->query({sql => "SELECT sku,quantity FROM orderline WHERE \
+ order_number='$order_number'",
+ wantarray => 1
+ })};
+ for my $item (@items) {
+ ($item->[2], $item->[3], $item->[4]) = @{$Tag->query({
+ sql => "SELECT description,price,weight FROM products WHERE sku='$item->[0]'",
+ wantarray => 1
+ })->[0]};
+ }
+ use Pikul;
+ Pikul::init($company, \@provisions);
+ my $tracking_number = Pikul::order(
+ $order_number,
+ $service,
+ "$::Variable->{COMPANY}",
+ "$::Variable->{PHONE}",
+ $origin,
+ "$::Variable->{ADDRESS}",
+ "$::Variable->{POSTAL_CODE}",
+ "$fname $lname",
+ $phone_day,
+ $Tag->query({sql => "SELECT code FROM $table WHERE district='$address2' AND city='$city' \
+ AND province='$state'",
+ wantarray => 1
+ })->[0]->[0],
+ $address1,
+ $zip,
+ $nitems,
+ \@items,
+ $subtotal
+ );
+ $Tag->query({sql => "UPDATE transactions SET tracking_number='$tracking_number' WHERE \
+ code='$order_number'"});
+ Pikul::cleanup();
+ return $tracking_number;
+}
+EOR