first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,483 @@
<?php
/**
* EasyPack Dispatch Orders
*
* @author WPDesk
* @category Admin
* @package EasyPack/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'EasyPack_Dispatch_Orders' ) ) :
/**
* EasyPack_Dispatch_Orders
*/
class EasyPack_Dispatch_Orders {
protected static $instance;
public function __construct() {
add_action( 'woocommerce_register_post_type', array( $this, 'register_post_types' ), 5 );
add_action( 'manage_dispatch_order_posts_custom_column', array( $this, 'manage_dispatch_order_posts_custom_column' ), 10, 2 );
add_filter( 'manage_edit-dispatch_order_columns', array( $this, 'manage_edit_dispatch_order_columns' ) ) ;
add_filter( 'bulk_actions-' . 'edit-dispatch_order', '__return_empty_array' );
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
}
public static function EasyPack_Dispatch_Orders() {
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
public function create_dispatch_order( $dispatch_point ) {
$parcels = $_POST['easypack_parcel'];
$parcel_ids = array();
foreach ( $parcels as $parcel ) {
$parcel_exploded = explode( '.', $parcel );
if ( $parcel_exploded[0] == 'easypack' ) {
$parcel_ids[] = $parcel_exploded[2];
}
if ( $parcel_exploded[0] == 'crossborder' ) {
$parcel_id = $parcel_exploded[2];
$order_id = $parcel_exploded[1];
$easypack_parcels = get_post_meta( $order_id, '_easypack_parcels', true );
foreach ( $easypack_parcels as $easypack_parcel ) {
if ( $easypack_parcel['crossborder_data']['id'] == $parcel_id ) {
$parcel_ids[] = $easypack_parcel['crossborder_data']['tracking_number'];
}
}
}
}
$args = array( 'parcel_ids' => $parcel_ids );
try {
$response = EasyPack_API()->dispatch_order( $dispatch_point, $args );
return $response['id'];
}
catch ( Exception $e ) {
throw $e;
}
}
public function create_manifest( $easypack_dispatch_point, $easypack_dispatch_number ) {
$ret = array();
$easypack_parcel_ids = $_POST['easypack_parcel'];
$all_parcels = array( 'crossborder' => array(), 'easypack' => array() );
foreach ( $easypack_parcel_ids as $easypack_parcel_id ) {
$order_parcel = explode( '.', $easypack_parcel_id );
$api = $order_parcel[0];
$order_id = $order_parcel[1];
$parcel_id = $order_parcel[2];
$all_parcels[$api][] = array( 'parcel_id' => $parcel_id, 'order_id' => $order_id );
}
foreach ( $all_parcels as $api => $api_parcels ) {
if ( count( $api_parcels ) ) {
try {
if ( $api == 'crossborder' ) {
$args = array( 'shipments' => array() );
foreach ( $api_parcels as $api_parcel ) {
$args['shipments'][] = array( 'id' => $api_parcel['parcel_id'] );
}
$manifest = CrossBorder_API()->manifest( $args );
}
$post = array( 'post_type' => 'dispatch_order', 'post_status' => 'publish' );
$post['post_title'] = $api . ' - ' . date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), current_time( 'timestamp' ) );
$post_id = wp_insert_post( $post );
$post = get_post( $post_id );
$post->post_title = $post_id . ' - ' . $post->post_title;
wp_update_post( $post );
update_post_meta( $post_id, '_parcels', $api_parcels );
if ( $api == 'crossborder' ) {
update_post_meta( $post_id, '_manifest', $manifest );
}
$sender = get_option( 'easypack_sender_email' );
if ( get_option( 'easypack_sender_company_name' ) ) {
$sender .= "\n" . get_option( 'easypack_sender_company_name' );
}
$sender .= "\n" . get_option( 'easypack_sender_first_name' ) . ' ' . get_option( 'easypack_sender_last_name' );
$sender .= "\n" . get_option( 'easypack_sender_street' ) . ' ' . get_option( 'easypack_sender_building_no' );
if ( get_option( 'easypack_sender_flat_no' ) ) {
$sender .= "/" . get_option( 'easypack_sender_flat_no' );
}
$sender .= "\n" . get_option( 'easypack_sender_post_code' ) . ' ' . get_option( 'easypack_sender_city' );
$sender .= "\nTel.:" . get_option( 'easypack_sender_phone' );
update_post_meta( $post_id, '_sender', $sender );
update_post_meta( $post_id, '_dispatch_number', $easypack_dispatch_number );
if ( $api == 'easypack' ) {
$dispatch_point = EasyPack_API()->dispatch_point( $easypack_dispatch_point );
update_post_meta( $post_id, '_dispatch_point', $dispatch_point );
}
update_post_meta( $post_id, '_api', $api );
update_post_meta( $post_id, '_parcel_ids', $api_parcels );
$ret[] = array( 'post_id' => $post_id, 'api' => $api ) ;
}
catch ( Exception $e ) {
throw $e;
}
}
}
foreach ( $easypack_parcel_ids as $easypack_parcel_id ) {
$order_parcel = explode( '.', $easypack_parcel_id );
$api = $order_parcel[0];
$order_id = $order_parcel[1];
$parcel_id = $order_parcel[2];
$easypack_parcels = get_post_meta( $order_id, '_easypack_parcels', true );
foreach ( $easypack_parcels as $key => $easypack_parcel ) {
if ( $api == 'crossborder' ) {
if ( $easypack_parcel['crossborder_data']['id'] == $parcel_id ) {
$easypack_parcels[$key]['dispatch_order'] = $post_id;
}
}
else {
if ( $easypack_parcel['easypack_data']['id'] == $parcel_id ) {
$easypack_parcels[$key]['dispatch_order'] = $post_id;
}
}
}
update_post_meta( $order_id, '_easypack_parcels', $easypack_parcels );
$dispatched = true;
foreach ( $easypack_parcels as $key => $easypack_parcel ) {
if ( empty( $easypack_parcels[$key]['dispatch_order'] ) ) $dispatched = false;
}
if ( $dispatched ) {
update_post_meta( $order_id, '_easypack_dispatched', '1' );
}
}
return $ret;
}
public function get_crossborder_manifest( $post_id ) {
$manifest = get_post_meta( $post_id, '_manifest' );
header( 'Location: ' . $manifest[0]['pdf_url'] );
}
public function create_easypack_manifest( $post_id ) {
$post = get_post( $post_id );
require_once( 'class-manifest-pdf.php' );
$width_full = 186;
$width2 = array( $width_full/2, $width_full/2);
$width3 = array( $width_full/3, $width_full/3, $width_full/3);
$width_col_size = 10;
$width3_2 = array( $width_col_size, ($width_full-$width_col_size)/2, ($width_full-$width_col_size)/2);
$width4 = array( $width_full/4, $width_full/4, $width_full/4, $width_full/4);
$width_col_size = 10;
$width4_2 = array( $width_col_size, $width_full/3 - $width_col_size, $width_full/3, $width_full/3);
$pdf = new EasyPack_Manifest_PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->Ln(5);
$pdf->AddFont('arialpl','','arialpl.php');
$pdf->SetFont('arialpl','', 11);
$text = iconv( 'utf-8', 'iso-8859-2', 'Potwierdzenie odebrania paczek nr ' . $post->ID );
$pdf->Cell( 0, 0, $text, 0, 0 , 'C' );
$pdf->Ln(5);
$dispatch_number = get_post_meta( $post_id, '_dispatch_number', true );
$text = iconv( 'utf-8', 'iso-8859-2', 'do zamówienia Odbioru nr ' . $dispatch_number );
$pdf->Cell( 0, 0, $text, 0, 0 , 'C' );
$pdf->Ln(15);
$text = iconv( 'utf-8', 'iso-8859-2', 'Data' );
$text .= ' ' . date_i18n( 'd/m/Y', strtotime( $post->post_date ) );
$pdf->Cell( 0, 0, $text, 0, 0 );
$pdf->Ln(5);
$text = iconv( 'utf-8', 'iso-8859-2', 'Oddział InPost' );
$pdf->Cell( $width3[0], 8, $text, 1, 'L' );
$text = iconv( 'utf-8', 'iso-8859-2', 'Nadawca' );
$pdf->Cell( $width3[1], 8, $text, 1, 'L' );
$text = iconv( 'utf-8', 'iso-8859-2', 'Adres odbioru' );
$pdf->Cell( $width3[2], 8, $text, 1, 'L' );
$pdf->Ln(8);
$pdf->Cell( $width3[0], 30, '', 1, 'L' );
$sender = get_post_meta( $post_id, '_sender', true );
$y = $pdf->GetY();
$x = $pdf->GetX();
$pdf->Cell( $width3[1], 30, '', 1, 'L' );
$pdf->SetXY( $x, $y );
$pdf->MultiCell( $width3[1], 5, $pdf->iconv( $sender ), 0, 'L' );
$pdf->SetXY( $x+$width3[1], $y );
$dispatch_point = get_post_meta( $post_id, '_dispatch_point', true );
$dispatch_address = '';
if ( $dispatch_point ) {
$dispatch_address = $dispatch_point['email'];
$dispatch_address .= "\n" . $dispatch_point['name'];
$dispatch_address .= "\n" . $dispatch_point['address']['street'] . ' ' . $dispatch_point['address']['building_no'];
if ( isset( $dispatch_point['address']['flat_no'] ) && trim($dispatch_point['address']['flat_no']) != '' ) {
$dispatch_address .= '/' . $dispatch_point['address']['flat_no'];
}
$dispatch_address .= "\n" . $dispatch_point['address']['post_code'] . ' ' . $dispatch_point['address']['city'];
$dispatch_address .= "\nTel.: " . $dispatch_point['phone'];
}
$y = $pdf->GetY();
$x = $pdf->GetX();
$pdf->Cell( $width3[1], 30, '', 1, 'L' );
$pdf->SetXY( $x, $y );
$pdf->MultiCell( $width3[2], 5, $pdf->iconv( $dispatch_address ), 0, 'L' );
$pdf->SetXY( $x+$width3[2], $y );
$pdf->Ln(30);
$pdf->Cell( $width_full, 16, $pdf->iconv( 'Uwagi:' ), 1, 'L' );
$pdf->Ln(16);
//
$pdf->Cell( $width4_2[0], 8, $pdf->iconv( 'Typ' ), 1, 0, 'C' );
$pdf->Cell( $width4_2[1], 8, $pdf->iconv( 'Kod paczki' ), 1, 0, 'C' );
$pdf->Cell( $width4_2[2], 8, $pdf->iconv( 'Numer referencyjny' ), 1, 0, 'C' );
$pdf->Cell( $width4_2[3], 8, $pdf->iconv( 'Odbiorca' ), 1, 0, 'C' );
$pdf->Ln(8);
//
$parcels = get_post_meta( $post_id, '_parcels', true );
$parcel_sizes = array( 'A' => 0, 'B' => 0, 'C' => 0 );
foreach ( $parcels as $parcel ) {
$order_id = $parcel['order_id'];
$parcel_id = $parcel['parcel_id'];
$easypack_parcels = get_post_meta( $order_id, '_easypack_parcels', true );
$easypack_data = EasyPack_Helper()->get_easypack_parcel_data( $easypack_parcels, $parcel_id );
$parcel_sizes[$easypack_data['size']]++;
$pdf->Cell( $width4_2[0], 25, $easypack_data['size'], 1, 0, 'C' );
$pdf->Code128($pdf->GetX()+5,$pdf->GetY()+1,$easypack_data['id'],$width4_2[1]-10,15);
$pdf->Cell( $width4_2[1], 25, '', 1, 0, 'C' );
$pdf->SetXY($pdf->GetX()-$width4_2[1], $pdf->GetY()+15);
$pdf->SetFont('arialpl','', 10);
$pdf->Cell( $width4_2[1], 10, $easypack_data['id'], 0, 0, 'C' );
$pdf->SetFont('arialpl','', 11);
$pdf->SetXY($pdf->GetX(), $pdf->GetY()-15);
$pdf->Cell( $width4_2[2], 25, '', 1, 0, 'C' );
$pdf->Cell( $width4_2[3], 25, $easypack_data['receiver_email'], 1, 0, 'C' );
$pdf->Ln(25);
}
$pdf->Ln(10);
$pdf->SetFont('arialpl','', 10);
if ( $pdf->GetY() > 140 ) {
$pdf->AddPage();
$pdf->Ln(10);
}
$pdf->Cell( $width4[0], 8, $pdf->iconv( 'Paczka gabarytu A' ), 1, 0, 'C' );
$pdf->Cell( $width4[1], 8, $pdf->iconv( 'Paczka gabarytu B' ), 1, 0, 'C' );
$pdf->Cell( $width4[2], 8, $pdf->iconv( 'Paczka gabarytu C' ), 1, 0, 'C' );
$pdf->Cell( $width4[2], 8, $pdf->iconv( 'Suma' ), 1, 0, 'C' );
$pdf->Ln(8);
$pdf->Cell( $width4[0], 8, $parcel_sizes['A'], 1, 0, 'C' );
$pdf->Cell( $width4[1], 8, $parcel_sizes['B'], 1, 0, 'C' );
$pdf->Cell( $width4[2], 8, $parcel_sizes['C'], 1, 0, 'C' );
$pdf->Cell( $width4[2], 8, $parcel_sizes['A'] + $parcel_sizes['B'] + $parcel_sizes['C'], 1, 0, 'C' );
$pdf->Ln(16);
$y = $pdf->GetY();
$pdf->Cell( 3, 3, '', 1, 0, 'C' );
$pdf->SetXY($pdf->GetX()+2, $pdf->GetY()-2);
$pdf->MultiCell( 80, 6, $pdf->iconv( "sprawdzono numery wszystkich paczek\n zgadza się / nie zgadza się - Uwagi\n\n.....................................................................\n\n....................................................................."
), 0, 'L' );
$pdf->SetXY( $pdf->GetX()+86, $y );
$pdf->Cell( 3, 3, '', 1, 0, 'C' );
$pdf->SetXY($pdf->GetX()+2, $pdf->GetY()-2);
$pdf->MultiCell( 100, 6, $pdf->iconv( "przeliczono ilość sztuk w poszczególnych gabarytach\n zgadza się / nie zgadza się - Uwagi\n\n..........................................................................\n\n.........................................................................."
), 0, 'L' );
$y = $pdf->GetY();
$pdf->Ln(5);
$pdf->Cell( 3, 3, '', 1, 0, 'C' );
$pdf->SetXY($pdf->GetX()+2, $pdf->GetY()-2);
$pdf->MultiCell( 100, 6, $pdf->iconv( "nie dokonano weryfikacji ilości i numerów przesyłek - rzeczywista liczba sztuk zostanie potwierdzona przez InPost dopiero po ich rejestracji w systemie śledzenia. Tylko przesyłki zarejestrowane w sytemie śledzenia są uważane za nadane.\nUwagi\n\n.....................................................................\n\n.....................................................................\n\nPodpis kuriera"
), 0, 'L' );
$pdf->SetXY( $pdf->GetX()+111, $y+5 );
$pdf->MultiCell( 100, 6, $pdf->iconv( "Podpis i pieczęć nadawcy"
), 0, 'L' );
//
$pdf->Output( 'D', 'manifest_' . $post_id . '.pdf' );
}
public function register_post_types() {
$labels = array(
'name' => _x( 'Dispatch Orders', 'post type general name', EasyPack::$text_domain ),
'singular_name' => _x( 'Dispatch Order', 'post type singular name', EasyPack::$text_domain ),
'menu_name' => _x( 'Dispatch Orders', 'admin menu', EasyPack::$text_domain ),
'name_admin_bar' => _x( 'Dispatch Order', 'add new on admin bar', EasyPack::$text_domain ),
'all_items' => __( 'All Dispatch Orders', EasyPack::$text_domain ),
'search_items' => __( 'Search Dispatch Orders', EasyPack::$text_domain ),
'not_found' => __( 'No Dispatch Orders found.', EasyPack::$text_domain ),
'not_found_in_trash' => __( 'No Dispatch Orders found in Trash.', EasyPack::$text_domain )
);
$args = array(
'labels' => $labels,
'description' => __( 'Dispatch Orders.', EasyPack::$text_domain ),
'public' => false,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => false,
'query_var' => true,
'rewrite' => false,
'capability_type' => 'post',
'capabilities' => array(
'create_posts' => 'do_not_allow',
'edit_post' => false,
'delete_post' => false,
),
'map_meta_cap' => true,
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title' )
);
register_post_type( 'dispatch_order', $args );
}
//public function manage_posts_custom_column
public function manage_edit_dispatch_order_columns( $columns ) {
unset($columns['date']);
unset($columns['cb']);
$columns['created'] = __( 'Created', EasyPack::$text_domain );
// $columns['status'] = __( 'Status', EasyPack::$text_domain );
$columns['action'] = __( 'Action', EasyPack::$text_domain );
return $columns;
}
function manage_dispatch_order_posts_custom_column( $column, $post_id ) {
global $post;
$api = get_post_meta( $post_id, '_api', true );
$status = get_post_meta( $post_id, '_status', true );
switch( $column ) {
case 'created' :
echo $post->post_date;
break;
case 'status' :
if ( $status == 'cancelled' )
_e( 'Cancelled', EasyPack::$text_domain );
break;
case 'action' :
if ( $status != 'cancelled' ) {
if ( $api == 'crossborder' ) {
$url = site_url( '?easypack_download=1&crossborder_manifest=' . $post_id );
}
else {
$url = site_url( '?easypack_download=1&easypack_manifest=' . $post_id );
}
$link = '<a href="' . $url . '" target="blank" class="button-primary">' . __( 'Print', EasyPack::$text_domain ) . '</a>';
echo $link;
echo ' ';
$url = admin_url( 'edit.php?post_type=dispatch_order&cancel=' . $post_id );
$link = '<a href="' . $url . '" class="button easypack_cancel_dispatch_order">' . __( 'Cancel', EasyPack::$text_domain ) . '</a>';
// echo $link;
}
break;
default :
break;
}
}
function cancel_dispatch_order( $post ) {
$order_parcel_ids = get_post_meta( $post->ID, '_parcel_ids', true );
$api = get_post_meta( $post->ID, '_api', true );
foreach ( $order_parcel_ids as $order_parcel_id ) {
$order_id = $order_parcel_id['order_id'];
$parcel_id = $order_parcel_id['parcel_id'];
$easypack_parcels = get_post_meta( $order_id, '_easypack_parcels', true );
foreach ( $easypack_parcels as $key => $easypack_parcel ) {
if ( $api == 'crossborder' ) {
if ( $easypack_parcel['crossborder_data']['id'] == $parcel_id ) {
unset( $easypack_parcels[$key]['dispatch_order'] );
}
}
else {
if ( $easypack_parcel['easypack_data']['id'] == $parcel_id ) {
unset( $easypack_parcels[$key]['dispatch_order'] );
}
}
}
update_post_meta( $order_id, '_easypack_parcels', $easypack_parcels );
delete_post_meta( $order_id, '_easypack_dispatched' );
}
update_post_meta( $post->ID, '_status', 'cancelled' );
}
function admin_notices() {
global $pagenow;
if ( $pagenow == 'edit.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'dispatch_order' && isset( $_GET['cancel'] ) ) {
$post = get_post( $_GET['cancel'] );
if ( $post ) {
if ( get_post_meta( $post->ID, '_status' ) == 'cancelled' ) {
?>
<div class="error">
<p><?php echo sprintf( __( 'Dispatch order %d already cancelled.', EasyPack::$text_domain ), $post->ID ); ?></p>
</div>
<?php
}
else {
$this->cancel_dispatch_order( $post );
?>
<div class="updated">
<p><?php echo sprintf( __( 'Dispatch order %d cancelled.', EasyPack::$text_domain ), $post->ID ); ?></p>
</div>
<?php
}
}
}
}
}
function EasyPack_Dispatch_Orders() {
return EasyPack_Dispatch_Orders::EasyPack_Dispatch_Orders();
}
EasyPack_Dispatch_Orders();
endif;

View File

@@ -0,0 +1,192 @@
<?php
/**
* EasyPack Manifest PDF
*
* @author WPDesk
* @category Admin
* @package EasyPack/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'EasyPack_Manifest_PDF' ) ) :
/**
* EasyPack_Manifest_PDF
*/
class EasyPack_Manifest_PDF extends PDF_Code128 {
function Footer() {
$this->SetY( -10 );
$this->SetFont( 'Arial', '', 8 );
$this->Cell( 0, 10, __( 'Page ', EasyPack::$text_domain ) . $this->PageNo() . ' / {nb}', 0, 0, 'R' );
$this->SetY( -10 );
}
/**
* Draws text within a box defined by width = w, height = h, and aligns
* the text vertically within the box ($valign = M/B/T for middle, bottom, or top)
* Also, aligns the text horizontally ($align = L/C/R/J for left, centered, right or justified)
* drawTextBox uses drawRows
*
* This function is provided by TUFaT.com
*/
function drawTextBox($strText, $w, $h, $align='L', $valign='T', $border=true)
{
$xi=$this->GetX();
$yi=$this->GetY();
$hrow=$this->FontSize;
$textrows=$this->drawRows($w,$hrow,$strText,0,$align,0,0,0);
$maxrows=floor($h/$this->FontSize);
$rows=min($textrows,$maxrows);
$dy=0;
if (strtoupper($valign)=='M')
$dy=($h-$rows*$this->FontSize)/2;
if (strtoupper($valign)=='B')
$dy=$h-$rows*$this->FontSize;
$this->SetY($yi+$dy);
$this->SetX($xi);
$this->drawRows($w,$hrow,$strText,0,$align,false,$rows,1);
if ($border)
$this->Rect($xi,$yi,$w,$h);
}
function drawRows($w, $h, $txt, $border=0, $align='J', $fill=false, $maxline=0, $prn=0) {
$cw=&$this->CurrentFont['cw'];
if($w==0)
$w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
$s=str_replace("\r",'',$txt);
$nb=strlen($s);
if($nb>0 && $s[$nb-1]=="\n")
$nb--;
$b=0;
if($border)
{
if($border==1)
{
$border='LTRB';
$b='LRT';
$b2='LR';
}
else
{
$b2='';
if(is_int(strpos($border,'L')))
$b2.='L';
if(is_int(strpos($border,'R')))
$b2.='R';
$b=is_int(strpos($border,'T')) ? $b2.'T' : $b2;
}
}
$sep=-1;
$i=0;
$j=0;
$l=0;
$ns=0;
$nl=1;
while($i<$nb)
{
//Get next character
$c=$s[$i];
if($c=="\n")
{
//Explicit line break
if($this->ws>0)
{
$this->ws=0;
if ($prn==1) $this->_out('0 Tw');
}
if ($prn==1) {
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
}
$i++;
$sep=-1;
$j=$i;
$l=0;
$ns=0;
$nl++;
if($border && $nl==2)
$b=$b2;
if ( $maxline && $nl > $maxline )
return substr($s,$i);
continue;
}
if($c==' ')
{
$sep=$i;
$ls=$l;
$ns++;
}
$l+=$cw[$c];
if($l>$wmax)
{
//Automatic line break
if($sep==-1)
{
if($i==$j)
$i++;
if($this->ws>0)
{
$this->ws=0;
if ($prn==1) $this->_out('0 Tw');
}
if ($prn==1) {
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
}
}
else
{
if($align=='J')
{
$this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0;
if ($prn==1) $this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
}
if ($prn==1){
$this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill);
}
$i=$sep+1;
}
$sep=-1;
$j=$i;
$l=0;
$ns=0;
$nl++;
if($border && $nl==2)
$b=$b2;
if ( $maxline && $nl > $maxline )
return substr($s,$i);
}
else
$i++;
}
//Last chunk
if($this->ws>0)
{
$this->ws=0;
if ($prn==1) $this->_out('0 Tw');
}
if($border && is_int(strpos($border,'B')))
$b.='B';
if ($prn==1) {
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
}
$this->x=$this->lMargin;
return $nl;
}
function iconv( $text ) {
return iconv( 'utf-8', 'iso-8859-2', $text );
}
}
endif;

View File

@@ -0,0 +1,68 @@
<?php
/**
* EasyPack Post Types
*
* @author WPDesk
* @category Admin
* @package EasyPack/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'EasyPack_Post_Types' ) ) :
/**
* EasyPack_Post_Types
*/
class EasyPack_Post_Types {
public static function init() {
add_action( 'woocommerce_register_post_type', array( __CLASS__, 'register_post_types' ), 5 );
}
public static function register_post_types() {
$labels = array(
'name' => _x( 'Dispatch Orders', 'post type general name', 'easypack' ),
'singular_name' => _x( 'Dispatch Order', 'post type singular name', 'easypack' ),
'menu_name' => _x( 'Dispatch Orders', 'admin menu', 'easypack' ),
'name_admin_bar' => _x( 'Dispatch Order', 'add new on admin bar', 'easypack' ),
'all_items' => __( 'All Dispatch Orders', 'easypack' ),
'search_items' => __( 'Search Dispatch Orders', 'easypack' ),
'not_found' => __( 'No Dispatch Orders found.', 'easypack' ),
'not_found_in_trash' => __( 'No Dispatch Orders found in Trash.', 'easypack' )
);
$args = array(
'labels' => $labels,
'description' => __( 'Dispatch Orders.', 'easypack' ),
'public' => false,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => false,
'query_var' => true,
'rewrite' => false,
'capability_type' => 'post',
'capabilities' => array(
'create_posts' => false,
'edit_post' => false,
'delete_post' => false,
),
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title' )
);
register_post_type( 'dispatch_order', $args );
}
}
endif;
EasyPack_Post_Types::init();

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,203 @@
<?php
/**
* EasyPack Shipment Manager List Table
*
* @author WPDesk
* @category Admin
* @package EasyPack/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'EasyPack_Shipment_Manager_List_Table' ) ) :
if( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
/**
* EasyPack_Shipment_Manager_List_Table
*/
class EasyPack_Shipment_Manager_List_Table extends WP_List_Table {
protected $data = array();
function __construct( $send_method ) {
parent::__construct();
global $post;
$args = array(
'post_type' => 'shop_order',
'post_status' => 'any',
'meta_query' => array(
array(
'key' => '_easypack_status',
'value' => array( 'prepared', 'created', 'ReadyToBeSent' ),
'compare' => 'IN',
),
array(
'key' => '_easypack_dispatched',
'value' => '',
'compare' => 'NOT EXISTS',
),
)
);
if ( $send_method != 'all' ) {
$args['meta_query'][] = array(
'key' => '_easypack_send_method',
'value' => $send_method,
'compare' => '=',
);
}
$query = new WP_Query($args);
while ( $query->have_posts() ) {
$query->the_post();
if ( $post->post_status == 'wc-cancelled' ) {
/* skip cancelled orders */
continue;
}
$order = wc_get_order($post->ID);
$order_id = $order->get_id();
$easypack_parcels = get_post_meta( $order_id, '_easypack_parcels', true );
if ( $easypack_parcels ) {
foreach ( $easypack_parcels as $key => $parcel ) {
$data = array();
if ( isset($parcel['easypack_data']) ) {
$data['package_number'] = $parcel['easypack_data']['id'];
if ( isset( $parcel['easypack_data']['tracking_number'] ) ) {
$data['package_number'] = $parcel['easypack_data']['tracking_number'];
}
$data['parcel'] = $parcel;
$data['send_method_display'] = __( 'Courier', EasyPack::$text_domain );
$send_method = get_post_meta( $order_id, '_easypack_send_method', true );
$data['send_method'] = $send_method;
if ( $send_method == 'parcel_machine' )
$data['send_method_display'] = __( 'Parcel Locker', EasyPack::$text_domain );
$data['status'] = $parcel['easypack_data']['status'];
if ( is_array( $parcel['easypack_data']['status'] ) ) {
$data['status'] = $parcel['easypack_data']['status']['code'];
}
$data['order'] = $order_id;
$data['shipping_address'] = $order->get_formatted_shipping_address();
if ( isset( $parcel['easypack_data']['target_machine_id'] ) ) {
$data['shipping_address'] = __( 'Parcel Locker ', EasyPack::$text_domain ) . ' ' . $parcel['easypack_data']['target_machine_id'];
}
$data['parcel_id'] = $parcel['easypack_data']['id'];
$data['order_id'] = $order_id;
$data['api'] = 'easypack';
}
if ( isset($parcel['crossborder_data']) ) {
$data['package_number'] = $parcel['crossborder_data']['id'];
$data['package_number'] = $parcel['crossborder_data']['tracking_number'];
$data['parcel'] = $parcel;
$data['send_method_display'] = __( 'Courier', EasyPack::$text_domain );
$send_method = get_post_meta( $order_id, '_easypack_send_method', true );
$data['send_method'] = $send_method;
if ( $send_method == 'parcel_machine' )
$data['send_method_display'] = __( 'Parcel Locker', EasyPack::$text_domain );
$data['status'] = $parcel['crossborder_data']['status']['code'];
$data['order'] = $order_id;
$data['shipping_address'] = $order->get_formatted_shipping_address();
if ( isset( $parcel['crossborder_data']['target_machine_id'] ) ) {
$data['shipping_address'] = __( 'Parcel Locker ', EasyPack::$text_domain ) . ' ' . $parcel['crossborder_data']['target_machine_id'];
}
$data['parcel_id'] = $parcel['crossborder_data']['id'];
$data['order_id'] = $order_id;
$data['api'] = 'crossborder';
}
$this->data[] = $data;
}
}
}
wp_reset_postdata();
}
function bulk_actions( $which = '' ) {
}
function column_cb($item) {
return sprintf(
'<input class="easypack_parcel" type="checkbox" name="easypack_parcel[]" value="%s" />', $item['api'] . '.' . $item['order_id'] . '.' . $item['parcel_id'] . '.' . $item['send_method'] . '.' . $item['status']
);
}
function column_order( $item ) {
$link = '<a href="'. admin_url( 'post.php?post=' . $item['order'] . '&action=edit' ) .'" >';
$link .= '#' . $item['order'];
$link .= '</a>';
return $link;
}
function column_default( $item, $column_name ) {
switch( $column_name ) {
case 'package_number':
case 'send_method':
case 'send_method_display':
case 'status':
case 'order':
case 'shipping_address':
return $item[ $column_name ];
default:
return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
}
}
function get_columns(){
$gb = EasyPack_API()->api_country() === 'GB';
/*if (true === $gb) {
$k = null;
$v= null;
} else {
$k = 'send_method_display';
$v = __( 'Send method', EasyPack::$text_domain );
}*/
$k = 'send_method_display';
$v = __( 'Send method', EasyPack::$text_domain );
$columns = array(
'cb' => '<input type="checkbox" />',
'package_number' => __( 'Package', EasyPack::$text_domain ),
$k => $v,
'status' => __( 'Status', EasyPack::$text_domain ),
'order' => __( 'Order', EasyPack::$text_domain ),
'shipping_address' => __( 'Shipping address', EasyPack::$text_domain ),
// 'parcel' => __( 'Parcel', EasyPack::$text_domain ),
);
return $columns;
}
function get_hidden_columns() {
return array();
}
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
$per_page = 5000000;
$current_page = $this->get_pagenum();
$total_items = count( $this->data );
$this->found_data = $this->data;
$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $per_page
) );
$this->items = $this->data;
}
}
endif;

View File

@@ -0,0 +1,109 @@
<?php
/**
* EasyPack Shipment Manager
*
* @author WPDesk
* @category Admin
* @package EasyPack/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'EasyPack_Shipment_Manager' ) ) :
/**
* EasyPack_Shipment_Manager
*/
class EasyPack_Shipment_Manager {
public static function init() {
add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) );
}
public static function admin_menu() {
global $menu;
$menu_pos = 56;
while ( isset( $menu[$menu_pos] ) ) {
$menu_pos++;
}
if ( EasyPack_API()->api_country() != '--' ) {
$icon_svg = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjI0Ni45OTk5OTk5OTk5OTk5NyIgaGVpZ2h0PSIyMjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6c3ZnPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiA8Zz4KICA8dGl0bGU+TGF5ZXIgMTwvdGl0bGU+CiAgPGcgaWQ9InN2Z18xIiBzdHJva2U9Im51bGwiPgogICA8cGF0aCBpZD0ic3ZnXzciIGQ9Im0xMDEuNTYxMDQsMTEwLjY3NDkyYzAsMCAtMTEuNjQ2MzcsNC41MDMxIC0yNi4wMTU5LDQuNTAzMWMtMTQuMzY4MTQsMCAtMjYuMDE1OSwtNC41MDMxIC0yNi4wMTU5LC00LjUwMzFzMTEuNjQ3NzUsLTQuNTAwMzMgMjYuMDE1OSwtNC41MDAzM2MxNC4zNjk1MywwIDI2LjAxNTksNC41MDAzMyAyNi4wMTU5LDQuNTAwMzMiIGZpbGw9IiNGRkNDMDAiIHN0cm9rZT0ibnVsbCIvPgogICA8cGF0aCBpZD0ic3ZnXzgiIGQ9Im0xMzcuNTM0NjUsNDQuNDYwM2MwLDAgLTEwLjMyMDA2LC02Ljk0OTY1IC0xOC4zNTM5OSwtMTguNjI3ODNjLTguMDMzOTQsLTExLjY3NjggLTEwLjc0MDUsLTIzLjY1OTI0IC0xMC43NDA1LC0yMy42NTkyNHMxMC4zMTg2OCw2Ljk0ODI3IDE4LjM1Mzk5LDE4LjYyNTA3YzguMDMzOTQsMTEuNjc5NTYgMTAuNzQwNSwyMy42NjIwMSAxMC43NDA1LDIzLjY2MjAxIiBmaWxsPSIjRkZDQzAwIiBzdHJva2U9Im51bGwiLz4KICAgPHBhdGggaWQ9InN2Z185IiBkPSJtMTExLjE4NjgzLDczLjAzMjAxYzAsMCAtMTIuNDM4ODQsLTEuMzg1NzggLTI1LjEyNTI0LC03Ljk5OTM2Yy0xMi42ODY0LC02LjYxMjIgLTIwLjgxNDM4LC0xNS45NDc1NSAtMjAuODE0MzgsLTE1Ljk0NzU1czEyLjQzODg0LDEuMzg1NzggMjUuMTI1MjQsNy45OTkzNmMxMi42ODY0LDYuNjEyMiAyMC44MTQzOCwxNS45NDc1NSAyMC44MTQzOCwxNS45NDc1NSIgZmlsbD0iI0ZGQ0MwMCIgc3Ryb2tlPSJudWxsIi8+CiAgIDxwYXRoIGlkPSJzdmdfMTAiIGQ9Im0xMzUuNzU4ODYsMTMwLjc2ODc1YzcuNTI5MTMsLTIuMjg0NzQgMTMuOTA0ODMsLTUuNjE5MTkgMTMuOTA0ODMsLTUuNjE5MTlzLTE3LjczNTc5LC00LjkzMDQ1IC0xNi40MzU3NSwtMjMuNDU0NTVjNC4wNzI5OCwtMzAuMzk3MjkgMjguNjgzNzQsLTU0LjI2MTIyIDU5LjQ5NDU1LC01OC4xMDMyM2MtMy4yNjgwNiwtMC40NTA4NiAtNi42MDUyOCwtMC42ODczNiAtMTAuMDAxOTcsLTAuNjcyMTVjLTM4LjEwODk4LDAuMTY4NzMgLTY4Ljg2MzA5LDMwLjU5NTA2IC02OC42OTE2LDY3Ljk1NzIyYzAuMTcwMTEsMzcuMzYwNzcgMzEuMjA0OTcsNjcuNTEwNSA2OS4zMTI1Nyw2Ny4zNDMxNmMzLjE3ODE3LC0wLjAxMzgzIDYuMzAxMDIsLTAuMjU3MjQgOS4zNjMwMSwtMC42Nzc2OGMtMjcuMDQwNzEsLTMuMzc4NzEgLTQ5LjA1MDAyLC0yMi4wNzE1NCAtNTYuOTQ1NjUsLTQ2Ljc3MzU3bDAuMDAwMDEsLTAuMDAwMDF6IiBmaWxsPSIjRkZDQzAwIi8+CiAgIDxwYXRoIGlkPSJzdmdfMTEiIGQ9Im0xMzcuNTM0NjUsMTc2LjYzMjNjMCwwIC0xMC4zMjAwNiw2Ljk0OTY1IC0xOC4zNTM5OSwxOC42MjkyMWMtOC4wMzM5NCwxMS42NzU0MSAtMTAuNzQwNSwyMy42NjA2MiAtMTAuNzQwNSwyMy42NjA2MnMxMC4zMTg2OCwtNi45NDk2NSAxOC4zNTM5OSwtMTguNjI3ODNjOC4wMzM5NCwtMTEuNjc2OCAxMC43NDA1LC0yMy42NjIwMSAxMC43NDA1LC0yMy42NjIwMSIgZmlsbD0iI0ZGQ0MwMCIgc3Ryb2tlPSJudWxsIi8+CiAgIDxwYXRoIGlkPSJzdmdfMTIiIGQ9Im0xMTEuMTg2ODMsMTQ4LjA2MTk3YzAsMCAtMTIuNDM4ODQsMS4zODU3OCAtMjUuMTI1MjQsNy45OTkzNmMtMTIuNjg2NCw2LjYxMDgxIC0yMC44MTQzOCwxNS45NDYxNyAtMjAuODE0MzgsMTUuOTQ2MTdzMTIuNDM4ODQsLTEuMzg1NzggMjUuMTI1MjQsLTcuOTk3OThzMjAuODE0MzgsLTE1Ljk0NzU1IDIwLjgxNDM4LC0xNS45NDc1NSIgZmlsbD0iI0ZGQ0MwMCIgc3Ryb2tlPSJudWxsIi8+CiAgPC9nPgogPC9nPgo8L3N2Zz4=';
add_menu_page( __('InPost', EasyPack::$text_domain ), __('InPost', EasyPack::$text_domain ), 'manage_options', 'inpost', null, $icon_svg, $menu_pos );
add_submenu_page( 'inpost', __( 'Shipments', EasyPack::$text_domain ), __( 'Shipments', EasyPack::$text_domain ), 'manage_options', 'easypack_shipment', array( __CLASS__, 'easypack_shipment' ) );
if ( EasyPack_API()->api_country() == 'PL' ) {
add_submenu_page( 'inpost', __( 'Dispatch Orders', EasyPack::$text_domain ), __( 'Dispatch Orders', EasyPack::$text_domain ), 'manage_options', 'edit.php?post_type=dispatch_order' );
}
remove_submenu_page( 'inpost', 'inpost' );
}
}
public static function easypack_shipment() {
require_once('class-shipment-manager-list-table.php' );
$dispatch_points = EasyPack_API()->customer_dispatch_points_options();
$dispatch_point = get_option( 'easypack_default_dispatch_point' );
if ( EasyPack_API()->api_country() == 'PL' || EasyPack_API()->api_country() == 'GB' ) {
$send_methods = array(
'all' => __( 'All', EasyPack::$text_domain ),
'parcel_machine' => __( 'Parcel Locker', EasyPack::$text_domain ),
'courier' => __( 'Courier', EasyPack::$text_domain ),
);
}
else {
$send_methods = array(
'courier' => __( 'Courier', EasyPack::$text_domain ),
);
}
if ( isset( $_POST['easypack_create_manifest_input'] ) && $_POST['easypack_create_manifest_input'] == 1 ) {
try {
$dispatch_order_id = EasyPack_Dispatch_Orders()->create_dispatch_order( $_POST['easypack_dispatch_point'] );
$manifests = EasyPack_Dispatch_Orders()->create_manifest( $_POST['easypack_dispatch_point'], $dispatch_order_id );
$message = __('Created manifests ', EasyPack::$text_domain );
foreach ( $manifests as $manifest ) {
if ( $manifest['api'] == 'crossborder' ) {
$url = site_url( '?easypack_download=1&crossborder_manifest=' . $manifest['post_id'] );
}
else {
$url = site_url( '?easypack_download=1&easypack_manifest=' . $manifest['post_id'] );
}
$link = ' <a href="' . $url . '" target="blank" class="">' . $manifest['post_id'] . '</a>, ';
$message .= $link;
}
$message = trim( trim( $message ), ',' );
?>
<div class="updated">
<p><?php echo $message; ?></p>
</div>
<?php
}
catch ( Exception $e ) {
$class = "error";
$message = __( 'Error while creating manifest: ', EasyPack::$text_domain ) . $e->getMessage();
echo "<div class=\"$class\"> <p>$message</p></div>";
}
}
$send_method = 'courier';
if ( isset( $_GET['send_method'] ) ) {
$send_method = $_GET['send_method'];
}
$shipment_manager_list_table = new EasyPack_Shipment_Manager_List_Table( $send_method );
include( 'views/html-shipment-manager.php' );
}
}
endif;
EasyPack_Shipment_Manager::init();

View File

@@ -0,0 +1,258 @@
<div class="wrap">
<div id="icon-users" class="icon32"></div>
<h2><?php _e( 'InPost Shipments' , EasyPack::$text_domain ); ?></h2>
<?php $shipment_manager_list_table->prepare_items(); ?>
<?php $gb = EasyPack_API()->api_country() === 'GB';?>
<form method="get">
<input type="hidden" name="page" value="easypack_shipment">
<?php if ( EasyPack_API()->api_country() == 'PL' ) : ?>
<div style="float:left;">
<?php
$params = array(
'type' => 'select',
'options' => $dispatch_points,
'class' => array('wc-enhanced-select'),
'label' => __('Dispatch point ', EasyPack::$text_domain),
);
woocommerce_form_field('dispatch_point', $params, $dispatch_point );
?>
</div>
<div style="float:left;">
<p>&nbsp;
<span class="tips" data-tip="<?php esc_attr_e( 'From the list, select the packages that you want to be sent by courier.', EasyPack::$text_domain ); ?>">
<button disabled id="easypack_get_courier" class="button-primary"><?php _e( 'Get courier', EasyPack::$text_domain ); ?></button>&nbsp;
</span>
</p>
</div>
<div style="float:left;">
<p><span id="easypack_spinner_get_courier" class="spinner"></span></p>
</div>
<div style="clear:both;"></div>
<?php endif; ?>
<?php if (false === $gb):?>
<div style="float:left;">
<?php
$params = array(
'type' => 'select',
'options' => $send_methods,
'class' => array('wc-enhanced-select'),
'label' => __('Send method ', EasyPack::$text_domain ),
);
woocommerce_form_field('send_method', $params, $send_method );
?>
</div>
<div style="float:left;">
<p>&nbsp;<input class="button button-primary" type="submit" value="<?php _e( 'Filter parcels', EasyPack::$text_domain ); ?>" /></p>
</div>
<?php endif?>
<div style="clear:both;"></div>
<div style="float:left;">
<p>
<?php if ( EasyPack_API()->api_country() == 'PL' ) : ?>
<span>
<?php else : ?>
<span class="tips" data-tip="<?php esc_attr_e( 'From the list, select the packages that you want to be collected to be sent. If Courier has been chosen, the collection of your packages by a courier will be arranged.', EasyPack::$text_domain ); ?>">
<?php endif; ?>
<button id="easypack_get_stickers" class="button-primary" href=""><?php _e( 'Get stickers', EasyPack::$text_domain ); ?></button>&nbsp;
</span>
</p>
</div>
<div style="float:left;">
<p><span id="easypack_spinner_get_stickers" class="spinner"></span></p>
</div>
<div style="clear:both;"></div>
<?php /*
<div style="float:left;">
<p>
<a id="easypack_create_manifest" class="button-primary" href=""><?php _e( 'Create manifest', EasyPack::$text_domain ); ?></a>
</p>
</div>
<div style="float:left;">
<p><span id="easypack_spinner_create_manifest" class="spinner"></span></p>
</div>
<div style="clear:both;"></div>
*/ ?>
</form>
<form id="easypack_shipment_form" method="post">
<input type="hidden" id="easypack_create_manifest_input" name="easypack_create_manifest_input" value="0" />
<input type="hidden" id="easypack_dispatch_point" name="easypack_dispatch_point" value="0" />
<input type="hidden" name="page" value="easypack_shipment">
<?php $shipment_manager_list_table->display(); ?>
</form>
</div>
<script type="text/javascript">
jQuery('#easypack_get_courier_old').click(function () {
jQuery(this).attr('disabled',true);
jQuery("#easypack_spinner_get_courier").addClass("is-active");
console.log('get_courier');
var parcels = [];
var count_parcels = 0;
jQuery('input.easypack_parcel').each(function(i) {
if ( jQuery(this).attr('checked') ) {
parcels[i] = jQuery(this).val();
count_parcels++;
}
});
if ( count_parcels == 0 ) {
alert('<?php _e( 'No parcels selected.', EasyPack::$text_domain ) ?>');
jQuery("#easypack_spinner_get_courier").removeClass("is-active");
jQuery('#easypack_get_courier').attr('disabled',false);
return false;
}
var data = {
action: 'easypack',
easypack_action: 'easypack_dispatch_order',
security: easypack_nonce,
parcels: parcels,
dispatch_point: jQuery('#dispatch_point').val()
};
jQuery.post(ajaxurl, data, function(response) {
console.log(response);
if ( response != 0 ) {
response = JSON.parse(response);
console.log(response);
if (response.status == 'ok' ) {
return false;
}
else {
alert(response.message);
}
}
else {
alert('Bad response.');
}
jQuery('#easypack_get_courier').attr('disabled',false);
jQuery("#easypack_spinner_get_courier").removeClass("is-active");
});
console.log(parcels);
return false;
})
jQuery('#easypack_get_courier').click(function () {
var parcels = [];
var count_parcels = 0;
jQuery('input.easypack_parcel').each(function(i) {
if ( jQuery(this).attr('checked') ) {
parcels[i] = jQuery(this).val();
count_parcels++;
}
});
if ( count_parcels == 0 ) {
alert('<?php _e( 'No parcels selected.', EasyPack::$text_domain ) ?>');
jQuery("#easypack_spinner_get_stickers").removeClass("is-active");
return false;
}
jQuery('#easypack_create_manifest_input').val(1);
jQuery('#easypack_dispatch_point').val(jQuery('#dispatch_point').val());
jQuery("#easypack_shipment_form").submit();
return false;
});
jQuery('#easypack_get_stickers').click(function () {
jQuery(this).attr('disabled',true);
jQuery("#easypack_spinner_get_stickers").addClass("is-active");
console.log('get_stickers');
var parcels = [];
var count_parcels = 0;
jQuery('input.easypack_parcel').each(function(i) {
if ( jQuery(this).attr('checked') ) {
parcels[i] = jQuery(this).val();
count_parcels++;
}
});
if ( count_parcels == 0 ) {
alert('<?php _e( 'No parcels selected.', EasyPack::$text_domain ) ?>');
jQuery("#easypack_spinner_get_stickers").removeClass("is-active");
jQuery('#easypack_get_stickers').attr('disabled',false);
return false;
}
var data = {
action: 'easypack',
easypack_action: 'easypack_create_stickers',
security: easypack_nonce,
parcels: parcels,
};
jQuery.post(ajaxurl, data, function(response) {
console.log(response);
if ( response != 0 ) {
response = JSON.parse(response);
console.log(response);
if (response.status == 'ok' ) {
var url = '<?php echo site_url('?easypack_download=1&easypack_file='); ?>' + response.file + '&security=<?php echo wp_create_nonce( 'easypack_nonce' ); ?>';
console.log(url);
window.open( url, "_blank");
}
else {
alert(response.message);
}
}
else {
alert('Bad response.');
}
jQuery('#easypack_get_stickers').attr('disabled',false);
jQuery("#easypack_spinner_get_stickers").removeClass("is-active");
});
console.log(parcels);
return false;
})
jQuery('#easypack_create_manifest').click(function () {
var parcels = [];
var count_parcels = 0;
jQuery('input.easypack_parcel').each(function(i) {
if ( jQuery(this).attr('checked') ) {
parcels[i] = jQuery(this).val();
count_parcels++;
}
});
if ( count_parcels == 0 ) {
alert('<?php _e( 'No parcels selected.', EasyPack::$text_domain ) ?>');
jQuery("#easypack_spinner_get_stickers").removeClass("is-active");
return false;
}
jQuery('#easypack_create_manifest_input').val(1);
jQuery('#easypack_dispatch_point').val(jQuery('#dispatch_point').val());
jQuery("#easypack_shipment_form").submit();
return false;
});
jQuery('.easypack_parcel').change(function() {
var easypack_get_courier_disabled = false;
var easypack_get_courier_count = 0;
jQuery('.easypack_parcel').each(function() {
if ( jQuery(this).is(':checked') ) {
easypack_get_courier_count++;
var cb_split = (jQuery(this).val()).split(".");
if (cb_split[3] != 'courier') easypack_get_courier_disabled = true;
if (cb_split[4] != 'prepared' && cb_split[4] != 'ReadyToBeSent') easypack_get_courier_disabled = true;
}
});
if (easypack_get_courier_count == 0) easypack_get_courier_disabled = true;
jQuery('#easypack_get_courier').attr('disabled',easypack_get_courier_disabled);
});
</script>