| 1 |
<?php |
| 2 |
|
| 3 |
namespace Metaboxes; |
| 4 |
|
| 5 |
use DateTime; |
| 6 |
use Mbe_Shipping_Csv_Editor_Pickup_Addresses; |
| 7 |
use Mbe_Shipping_Helper_Data; |
| 8 |
|
| 9 |
abstract class AdvancedReturnAddressData { |
| 10 |
|
| 11 |
public static function add( $item, $screens = [] ) { |
| 12 |
$screens = ! is_array( $screens ) ? [ $screens ] : $screens; |
| 13 |
add_meta_box( MBE_ESHIP_ID . '_advanced_return_address_data_form_meta_box', |
| 14 |
' ', |
| 15 |
[ self::class, 'html' ], |
| 16 |
$screens, |
| 17 |
'normal', |
| 18 |
'default', |
| 19 |
$item |
| 20 |
); |
| 21 |
} |
| 22 |
|
| 23 |
public static function html( $orderId ) { |
| 24 |
|
| 25 |
$helper = new Mbe_Shipping_Helper_Data(); |
| 26 |
$ws = new \Mbe_Shipping_Model_Ws(); |
| 27 |
|
| 28 |
$originalShipmentData = $ws->getShipmentItems( $orderId ); |
| 29 |
$originalShipmentSender = $originalShipmentData->ShipmentsFullInfo->ShipmentFullInfo->SenderInfo; |
| 30 |
$originalShipmentReceiver = $originalShipmentData->ShipmentsFullInfo->ShipmentFullInfo->ReceiverInfo; |
| 31 |
|
| 32 |
$nextMonday = new DateTime( 'next monday' ); |
| 33 |
$today = new DateTime( 'today' ); |
| 34 |
$fifteenMinutesBeforeNoon = new DateTime( 'front of 10AM' ); |
| 35 |
$noon = new DateTime( '10AM' ); |
| 36 |
$countries = new \WC_Countries(); |
| 37 |
// $shopCountry = $helper->getCountry(); |
| 38 |
?> |
| 39 |
|
| 40 |
<div style="width: 100%; overflow: hidden;"> |
| 41 |
<!--Sender --> |
| 42 |
<div style="float: left; width: 28%; margin-right: 2%;"><h3><?php esc_html_e( 'Sender Address', 'mail-boxes-etc' ); ?></h3> |
| 43 |
|
| 44 |
<div style="margin-bottom: 15px;"> |
| 45 |
<label for="sender_trade_name" style="display: block; font-weight: bold;"><?php esc_html_e( 'Trade Name', 'mail-boxes-etc' ); ?> <span |
| 46 |
style="color: #c03939">*</span></label> |
| 47 |
<input type="text" name="sender_trade_name" id="sender_trade_name" class="regular-text" maxlength="100" |
| 48 |
style="width: 100%;" value="<?php echo $originalShipmentReceiver->CompanyName??'' ?>" required> |
| 49 |
</div> |
| 50 |
<div style="margin-bottom: 15px;"> |
| 51 |
<label for="sender_address_1" style="display: block; font-weight: bold;"><?php esc_html_e( 'Address 1', 'mail-boxes-etc' ); ?> <span |
| 52 |
style="color: #c03939">*</span></label> |
| 53 |
<input type="text" name="sender_address_1" id="sender_address_1" class="regular-text" maxlength="200" |
| 54 |
style="width: 100%;" value="<?php echo $originalShipmentReceiver->Address??'' ?>" required> |
| 55 |
</div> |
| 56 |
<div style="margin-bottom: 15px;"> |
| 57 |
<label for="sender_address_2" style="display: block; font-weight: bold;"><?php esc_html_e( 'Address 2', 'mail-boxes-etc' ); ?></label> |
| 58 |
<input type="text" name="sender_address_2" id="sender_address_2" class="regular-text" maxlength="100" |
| 59 |
style="width: 100%;"> |
| 60 |
</div> |
| 61 |
<div style="margin-bottom: 15px;"> |
| 62 |
<label for="sender_address_3" style="display: block; font-weight: bold;"><?php esc_html_e( 'Address 3', 'mail-boxes-etc' ); ?></label> |
| 63 |
<input type="text" name="sender_address_3" id="sender_address_3" class="regular-text" maxlength="100" |
| 64 |
style="width: 100%;"> |
| 65 |
</div> |
| 66 |
<div style="margin-bottom: 15px;"> |
| 67 |
<label for="sender_postcode" style="display: block; font-weight: bold;"><?php esc_html_e( 'Postcode', 'mail-boxes-etc' ); ?> <span |
| 68 |
style="color: #c03939">*</span></label> |
| 69 |
<input type="text" name="sender_postcode" id="sender_postcode" class="regular-text" maxlength="12" |
| 70 |
style="width: 100%;" value="<?php echo $originalShipmentReceiver->ZipCode??'' ?>" required> |
| 71 |
</div> |
| 72 |
<div style="margin-bottom: 15px;"> |
| 73 |
<label for="sender_city" style="display: block; font-weight: bold;"><?php esc_html_e( 'City', 'mail-boxes-etc' ); ?> <span |
| 74 |
style="color: #c03939">*</span></label> |
| 75 |
<input type="text" name="sender_city" id="sender_city" class="regular-text" style="width: 100%;" maxlength="100" |
| 76 |
value="<?php echo $originalShipmentReceiver->City??'' ?>" required> |
| 77 |
</div> |
| 78 |
<div style="margin-bottom: 15px;"> |
| 79 |
<label for="sender_province" style="display: block; font-weight: bold;"><?php esc_html_e( 'Province', 'mail-boxes-etc' ); ?> <span |
| 80 |
style="color: #c03939"><?php echo $helper->getCountry()==='IT'?'*':''?></span></label> |
| 81 |
<input type="text" name="sender_province" id="sender_province" class="regular-text" maxlength="2" |
| 82 |
style="width: 100%;" value="<?php echo substr($originalShipmentReceiver->State??'', 0 ,2) ?>" <?php echo $helper->getCountry()==='IT'?'required':''?> > |
| 83 |
</div> |
| 84 |
<div style="margin-bottom: 15px;"> |
| 85 |
<label for="sender_country" style="display: block; font-weight: bold;"><?php esc_html_e( 'Country', 'mail-boxes-etc' ); ?> <span |
| 86 |
style="color: #c03939">*</span></label> |
| 87 |
<select id="sender_country" name="sender_country" style="width: 100%" required> |
| 88 |
<?php foreach ( $countries->get_countries() as $code=>$label ) { |
| 89 |
echo '<option value="'.esc_attr($code).'" '. (strtolower($originalShipmentReceiver->Country) === strtolower($label)?'selected':'') .'>'.esc_html($label).'</option>'; |
| 90 |
} ?> |
| 91 |
</select> |
| 92 |
</div> |
| 93 |
<div style="margin-bottom: 15px;"> |
| 94 |
<label for="sender_reference" style="display: block; font-weight: bold;"><?php esc_html_e( 'Reference', 'mail-boxes-etc' ); ?> <span |
| 95 |
style="color: #c03939">*</span></label> |
| 96 |
<input type="text" name="sender_reference" id="sender_reference" class="regular-text" maxlength="100" |
| 97 |
style="width: 100%;" value="<?php echo $originalShipmentReceiver->CompanyName??'' ?>" required> |
| 98 |
</div> |
| 99 |
<div style="margin-bottom: 15px;"> |
| 100 |
<label for="sender_telephone_1" style="display: block; font-weight: bold;"><?php esc_html_e( 'Telephone 1', 'mail-boxes-etc' ); ?> <span |
| 101 |
style="color: #c03939">*</span></label> |
| 102 |
<input type="text" name="sender_telephone_1" id="sender_telephone_1" class="regular-text" maxlength="50" |
| 103 |
style="width: 100%;" value="<?php echo $originalShipmentReceiver->Phone??'' ?>" required> |
| 104 |
</div> |
| 105 |
<div style="margin-bottom: 15px;"> |
| 106 |
<label for="sender_email_1" style="display: block; font-weight: bold;"><?php esc_html_e( 'E-mail 1', 'mail-boxes-etc' ); ?> <span |
| 107 |
style="color: #c03939">*</span></label> |
| 108 |
<input type="email" name="sender_email_1" id="sender_email_1" class="regular-text" maxlength="75" |
| 109 |
style="width: 100%;" value="<?php echo $originalShipmentReceiver->Emails??'' ?>" required> |
| 110 |
</div> |
| 111 |
<div style="margin-bottom: 15px;"> |
| 112 |
<label for="sender_fax" style="display: block; font-weight: bold;"><?php esc_html_e( 'Fax', 'mail-boxes-etc' ); ?></label> |
| 113 |
<input type="text" name="sender_fax" id="sender_fax" class="regular-text" style="width: 100%;"> |
| 114 |
</div> |
| 115 |
</div> |
| 116 |
<!-- Recipient--> |
| 117 |
<div style="float: left; width: 28%; margin-right: 2%;"><h3><?php esc_html_e( 'Recipient address', 'mail-boxes-etc' ); ?></h3> |
| 118 |
|
| 119 |
<div style="margin-bottom: 15px;"> |
| 120 |
<label for="receiver_trade_name" style="display: block; font-weight: bold;"><?php esc_html_e( 'Trade Name', 'mail-boxes-etc' ); ?> <span |
| 121 |
style="color: #c03939">*</span></label> |
| 122 |
<input type="text" name="receiver_trade_name" id="receiver_trade_name" class="regular-text" maxlength="100" |
| 123 |
style="width: 100%;" value="<?php echo $originalShipmentSender->CompanyName??'' ?>" required> |
| 124 |
</div> |
| 125 |
<div style="margin-bottom: 15px;"> |
| 126 |
<label for="receiver_address_1" style="display: block; font-weight: bold;"><?php esc_html_e( 'Address 1', 'mail-boxes-etc' ); ?> <span |
| 127 |
style="color: #c03939">*</span></label> |
| 128 |
<input type="text" name="receiver_address_1" id="receiver_address_1" class="regular-text" maxlength="200" |
| 129 |
style="width: 100%;" value="<?php echo $originalShipmentSender->Address??'' ?>" required> |
| 130 |
</div> |
| 131 |
<div style="margin-bottom: 15px;"> |
| 132 |
<label for="receiver_address_2" style="display: block; font-weight: bold;"><?php esc_html_e( 'Address 2', 'mail-boxes-etc' ); ?></label> |
| 133 |
<input type="text" name="receiver_address_2" id="receiver_address_2" class="regular-text" maxlength="100" |
| 134 |
style="width: 100%;"> |
| 135 |
</div> |
| 136 |
<div style="margin-bottom: 15px;"> |
| 137 |
<label for="receiver_address_3" style="display: block; font-weight: bold;"><?php esc_html_e( 'Address 3', 'mail-boxes-etc' ); ?></label> |
| 138 |
<input type="text" name="receiver_address_3" id="receiver_address_3" class="regular-text" maxlength="100" |
| 139 |
style="width: 100%;"> |
| 140 |
</div> |
| 141 |
<div style="margin-bottom: 15px;"> |
| 142 |
<label for="receiver_postcode" style="display: block; font-weight: bold;"><?php esc_html_e( 'Postcode', 'mail-boxes-etc' ); ?> <span |
| 143 |
style="color: #c03939">*</span></label> |
| 144 |
<input type="text" name="receiver_postcode" id="receiver_postcode" class="regular-text" maxlength="12" |
| 145 |
style="width: 100%;" value="<?php echo $originalShipmentSender->ZipCode??'' ?>" required> |
| 146 |
</div> |
| 147 |
<div style="margin-bottom: 15px;"> |
| 148 |
<label for="receiver_city" style="display: block; font-weight: bold;"><?php esc_html_e( 'City', 'mail-boxes-etc' ); ?> <span |
| 149 |
style="color: #c03939">*</span></label> |
| 150 |
<input type="text" name="receiver_city" id="receiver_city" class="regular-text" style="width: 100%;" maxlength="100" |
| 151 |
value="<?php echo $originalShipmentSender->City??'' ?>" required> |
| 152 |
</div> |
| 153 |
<div style="margin-bottom: 15px;"> |
| 154 |
<label for="receiver_province" style="display: block; font-weight: bold;"><?php esc_html_e( 'Province', 'mail-boxes-etc' ); ?> <span |
| 155 |
style="color: #c03939"><?php echo $helper->getCountry()==='IT'?'*':''?></span></label> |
| 156 |
<input type="text" name="receiver_province" id="receiver_province" class="regular-text" maxlength="2" |
| 157 |
style="width: 100%;" value="<?php echo substr($originalShipmentSender->State??'',0 ,2) ?>" <?php echo $helper->getCountry()==='IT'?'required':''?> > |
| 158 |
</div> |
| 159 |
<div style="margin-bottom: 15px;"> |
| 160 |
<label for="receiver_country" style="display: block; font-weight: bold;"><?php esc_html_e( 'Country', 'mail-boxes-etc' ); ?> <span |
| 161 |
style="color: #c03939">*</span></label> |
| 162 |
<select id="receiver_country" name="receiver_country" style="width: 100%" required> |
| 163 |
<?php foreach ( $countries->get_countries() as $code=>$label ) { |
| 164 |
echo '<option value="'.esc_attr($code).'" '. (strtolower($originalShipmentSender->Country) === strtolower($label)?'selected':'') .'>'.esc_html($label).'</option>'; |
| 165 |
} ?> |
| 166 |
</select> |
| 167 |
</div> |
| 168 |
<div style="margin-bottom: 15px;"> |
| 169 |
<label for="receiver_reference" style="display: block; font-weight: bold;"><?php esc_html_e( 'Reference', 'mail-boxes-etc' ); ?> <span |
| 170 |
style="color: #c03939">*</span></label> |
| 171 |
<input type="text" name="receiver_reference" id="receiver_reference" class="regular-text" maxlength="100" |
| 172 |
style="width: 100%;" value="<?php echo $originalShipmentSender->CompanyName??''?>" required> |
| 173 |
</div> |
| 174 |
<div style="margin-bottom: 15px;"> |
| 175 |
<label for="receiver_telephone_1" style="display: block; font-weight: bold;"><?php esc_html_e( 'Telephone 1', 'mail-boxes-etc' ); ?> <span |
| 176 |
style="color: #c03939">*</span></label> |
| 177 |
<input type="text" name="receiver_telephone_1" id="receiver_telephone_1" class="regular-text" maxlength="50" |
| 178 |
style="width: 100%;" value="<?php echo $originalShipmentSender->Phone??'' ?>" required> |
| 179 |
</div> |
| 180 |
<div style="margin-bottom: 15px;"> |
| 181 |
<label for="receiver_email_1" style="display: block; font-weight: bold;"><?php esc_html_e( 'E-mail 1', 'mail-boxes-etc' ); ?> <span |
| 182 |
style="color: #c03939">*</span></label> |
| 183 |
<input type="email" name="receiver_email_1" id="receiver_email_1" class="regular-text" maxlength="75" |
| 184 |
style="width: 100%;" value="<?php echo $originalShipmentSender->Emails??'' ?>" required> |
| 185 |
</div> |
| 186 |
<div style="margin-bottom: 15px;"> |
| 187 |
<label for="receiver_fax" style="display: block; font-weight: bold;"><?php esc_html_e( 'Fax', 'mail-boxes-etc' ); ?></label> |
| 188 |
<input type="text" name="receiver_fax" id="receiver_fax" class="regular-text" style="width: 100%;"> |
| 189 |
</div> |
| 190 |
</div> |
| 191 |
<!-- Pickup data--> |
| 192 |
<div style="float: left; width: 38%; "><h3><?php esc_html_e( 'Pickup Details', 'mail-boxes-etc' ); ?></h3> |
| 193 |
|
| 194 |
<div style="margin-bottom: 15px;"> |
| 195 |
<label for="pickup_date" style="display: block; font-weight: bold;"><?php esc_html_e( 'Pickup Date', 'mail-boxes-etc' ); ?> <span |
| 196 |
style="color: #c03939">*</span></label> |
| 197 |
<input id="pickup_date" name="pickup_date" type="date" style="width: 95%" |
| 198 |
value="<?php esc_html_e($item['date']??$nextMonday->format('Y-m-d')) ?>" |
| 199 |
min="<?php esc_html_e($today->format('Y-m-d')) ?>" |
| 200 |
required> |
| 201 |
<p class="description" style="font-size: 0.9em; color: #555; margin-top: 5px;"><?php esc_html_e( 'Select the date on which you would like courier pickup to take place. This date will be communicated directly to the courier. N.B. It is highly recommended that you choose a working day', 'mail-boxes-etc' ); ?></p> |
| 202 |
</div> |
| 203 |
<div style="margin-bottom: 15px;"> |
| 204 |
<label for="pickup_time_preferred_from" style="display: block; font-weight: bold;"><?php esc_html_e( 'Pickup Time - Preferred from', 'mail-boxes-etc' ); ?> <span style="color: #c03939">*</span></label> |
| 205 |
<input type="time" name="pickup_time_preferred_from" id="pickup_time_preferred_from" value="<?php echo esc_attr($fifteenMinutesBeforeNoon->format('H:i')) ?>" |
| 206 |
style="width: 100%;" required> |
| 207 |
<p class="description" style="font-size: 0.9em; color: #555; margin-top: 5px;"><?php esc_html_e( 'Minimum pickup time that will be communicated to the courier (N.B. pickup time is approximate and may not be observed by the final courier)', 'mail-boxes-etc' ); ?></p> |
| 208 |
</div> |
| 209 |
<div style="margin-bottom: 15px;"> |
| 210 |
<label for="pickup_time_pickup_time_preferred_to" style="display: block; font-weight: bold;"><?php esc_html_e( 'Pickup Time - Preferred to', 'mail-boxes-etc' ); ?> <span style="color: #c03939">*</span></label> |
| 211 |
<input type="time" name="pickup_time_preferred_to" id="pickup_time_preferred_to" value="<?php echo esc_attr($noon->format('H:i')) ?>" |
| 212 |
style="width: 100%;" required> |
| 213 |
<p class="description" style="font-size: 0.9em; color: #555; margin-top: 5px;"><?php esc_html_e( 'Maximum pickup time that will be communicated to the courier (N.B. pickup time is approximate and may not be observed by the final courier)', 'mail-boxes-etc' ); ?></p> |
| 214 |
</div> |
| 215 |
<div style="margin-bottom: 15px;"> |
| 216 |
<label for="pickup_time_alternative_from" style="display: block; font-weight: bold;"><?php esc_html_e( 'Pickup Time - Alternative from', 'mail-boxes-etc' ); ?></label> |
| 217 |
<input type="time" name="pickup_time_alternative_from" id="pickup_time_alternative_from" |
| 218 |
style="width: 100%;"> |
| 219 |
<p class="description" style="font-size: 0.9em; color: #555; margin-top: 5px;"><?php esc_html_e( 'Alternative minimum pickup time that will be communicated to the courier (N.B. pickup time is approximate and may not be observed by the final courier)', 'mail-boxes-etc' ); ?></p> |
| 220 |
</div> |
| 221 |
<div style="margin-bottom: 15px;"> |
| 222 |
<label for="pickup_time_alternative_to" style="display: block; font-weight: bold;"><?php esc_html_e( 'Pickup Time - Alternative to', 'mail-boxes-etc' ); ?></label> |
| 223 |
<input type="time" name="pickup_time_alternative_to" id="pickup_time_alternative_to" |
| 224 |
style="width: 100%;"> |
| 225 |
<p class="description" style="font-size: 0.9em; color: #555; margin-top: 5px;"><?php esc_html_e( 'Alternative maximum pickup time that will be communicated to the courier (N.B. pickup time is approximate and may not be observed by the final courier)', 'mail-boxes-etc' ); ?></p> |
| 226 |
</div> |
| 227 |
<div style="margin-bottom: 15px;"> |
| 228 |
<label for="pickup_notes" style="display: block; font-weight: bold;"><?php esc_html_e( 'Pickup notes', 'mail-boxes-etc' ); ?></label> |
| 229 |
<input type="text" name="pickup_notes" id="pickup_notes" class="regular-text" style="width: 100%;"> |
| 230 |
<p class="description" style="font-size: 0.9em; color: #555; margin-top: 5px;"><?php esc_html_e( 'Notes to be included within the pickup request and that will be forwarded to the final carrier', 'mail-boxes-etc' ); ?></p> |
| 231 |
</div> |
| 232 |
</div> |
| 233 |
|
| 234 |
</div> |
| 235 |
|
| 236 |
<div style="clear: both;"></div> |
| 237 |
|
| 238 |
|
| 239 |
<?php |
| 240 |
} |
| 241 |
|
| 242 |
} |