Guest User

Untitled

a guest
Jan 21st, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.71 KB | None | 0 0
  1. <?php
  2.  
  3. foreach($shipments as $shipment){
  4. $box = Boxes::model()->getBoxFromShipmentId($shipment->shipment_id);
  5. $box_item = BoxItems::model()->findByAttributes(array('box_id' => $box->box_id));
  6. $shipment_data = array();
  7. $s_address = Address::model()->getAddress($shipment->shipper_id); //shipper address
  8.  
  9. $shipment_data['Shipper'] = array(
  10. 'Contact' => array(
  11. 'PersonName' => $s_address->first_name.' '.$s_address->last_name,
  12. 'CompanyName' => $s_address->first_name.' '.$s_address->last_name,
  13. 'PhoneNumber' => $s_address->mobile),
  14. 'Address' => array(
  15. 'StreetLines' => array($s_address->street1),
  16. 'City' => $s_address->city,
  17. 'StateOrProvinceCode' => $s_address->state,
  18. 'PostalCode' => $s_address->zipcode,
  19. 'CountryCode' => $s_address->country_code)
  20. );
  21.  
  22. $r_address = Address::model()->getAddress($shipment->consignee_id); //recipient address
  23.  
  24. $shipment_data['Recipient'] = array(
  25. 'Contact' => array(
  26. 'PersonName' => $r_address->first_name.' '.$r_address->last_name,
  27. 'CompanyName' => $r_address->first_name.' '.$r_address->last_name,
  28. 'PhoneNumber' => $r_address->mobile),
  29. 'Address' => array(
  30. 'StreetLines' => array($r_address->street1),
  31. 'City' => $r_address->city,
  32. 'StateOrProvinceCode' => $r_address->state,
  33. 'PostalCode' => $r_address->zipcode,
  34. 'CountryCode' => $r_address->country_code,
  35. )
  36. );
  37.  
  38. $shipment_data['Recipient']['Contact']['PhoneNumber'] = preg_replace("/[^0-9\/]/","",$shipment_data['Recipient']['Contact']['PhoneNumber']);
  39. if(strlen($shipment_data['Recipient']['Contact']['PhoneNumber']) > 15) $shipment_data['Recipient']['Contact']['PhoneNumber'] = substr($shipment_data['Recipient']['Contact']['PhoneNumber'], 0, 15);
  40.  
  41. /*
  42. * CUSTOMER_REFERENCE : shipment id | logistic shipment id
  43. * INVOICE_NUMBER : box id
  44. * P_O_NUMBER : BOX ID
  45. */
  46. $shipment_data['CustomerReferences'] = array(
  47. '0' => array(
  48. 'CustomerReferenceType' => 'CUSTOMER_REFERENCE',
  49. 'Value' => 'GR'.$shipment->shipment_id
  50. ), // valid values CUSTOMER_REFERENCE, INVOICE_NUMBER, P_O_NUMBER and SHIPMENT_INTEGRITY
  51. '1' => array(
  52. 'CustomerReferenceType' => 'INVOICE_NUMBER',
  53. 'Value' => 'INV'.$shipment->shipment_id
  54. ),
  55. '2' => array(
  56. 'CustomerReferenceType' => 'P_O_NUMBER',
  57. 'Value' => 'PO'.$shipment->order_id
  58. )
  59. );
  60.  
  61. $shipment_data['Weight'] = array(
  62. 'Value' => (float)number_format($box->weight * self::LB_TO_KG,2),
  63. 'Units' => self::FEDEX_WT_UNIT
  64. );
  65.  
  66. $shipment_data['service_type'] = ($shipment->cod == 1)?COD:NON_COD;
  67.  
  68. $total_amount = $box_item->sales_price * $box_item->qty;
  69. $shipment_data['CodDetail']['CodCollectionAmount']= array('Currency' => 'INR', 'Amount' => $total_amount);
  70. $shipment_data['CustomsClearanceDetail'] = array(
  71. 'DutiesPayment' => array(
  72. 'PaymentType' => 'SENDER',
  73. 'Payor' => array(
  74. 'ResponsibleParty' => array(
  75. 'AccountNumber' => Yii::app()->fedex->getProperty('shipaccount'),
  76. 'Contact' => array('Title' => 'Fedex'),
  77. 'Address' => array('CountryCode' => 'IN'),
  78.  
  79. )
  80. )
  81. ),
  82. 'DocumentContent' => 'DOCUMENTS_ONLY',
  83. 'CustomsValue' => array(
  84. 'Currency' => 'INR',
  85. 'Amount' => $total_amount,
  86. ),
  87. 'CommercialInvoice' => array(
  88. 'Purpose' => 'SOLD'
  89. ),
  90. 'Commodities' => array(
  91. 'Name' => $box_item->description,
  92. 'NumberOfPieces' => $box_item->qty,
  93. 'Description' => $box_item->description,
  94. 'CountryOfManufacture' => 'IN',
  95. 'HarmonizedCode' => 1004000010,
  96. 'Weight' => array(
  97. 'Units' => self::FEDEX_WT_UNIT,
  98. 'Value' => (float)number_format($box->weight * self::LB_TO_KG,2),
  99. ),
  100. 'Quantity' => $box_item->qty,
  101. 'QuantityUnits' => 'EA',
  102. 'UnitPrice' => array(
  103. 'Currency' => 'INR',
  104. 'Amount' => $total_amount
  105. ),
  106. 'CustomsValue' => array(
  107. 'Currency' => 'INR',
  108. 'Amount' => $total_amount
  109. )
  110.  
  111. )
  112. );
  113.  
  114. $tracking = Yii::app()->fedex->createShipment($shipment_data);
  115.  
  116. if($tracking != false){
  117. $shipment_data = array();
  118. $shipment_data['shipment_id'] = $shipment->shipment_id;
  119. $shipment_data['courier_tracking_id'] = $tracking['tracking_number'];
  120. $response[$shipment->shipment_id] = $tracking['tracking_number'];
  121. Shipment::model()->updateShipment($shipment_data);
  122.  
  123. //create image
  124. $codlable_file_name = Yii::app()->utility->createFile('ship_codlabel_'.$tracking['tracking_number'].rand(0,9999).'.png',Yii::getPathOfAlias('fedex_path').'/cod_ground_return_label/',$tracking['cod_ground_return_label']);
  125. $shipping_ground_label_file_name = Yii::app()->utility->createFile('shipping_ground_label_'.$tracking['tracking_number'].rand(0,9999).'.png',Yii::getPathOfAlias('fedex_path').'/shipping_ground_label/',$tracking['shipping_ground_label']);
  126. //fedex tracking
  127. $fedex_data = array();
  128. $fedex_data['courier_tracking_id'] = $tracking['tracking_number'];
  129. $fedex_data['form_id'] = $tracking['form_id'];
  130. $fedex_data['destination_location_id'] = $tracking['destination_location_id'];
  131. $fedex_data['shipping_ground_label'] = 'uploads/fedex/shipping_ground_label/'.$shipping_ground_label_file_name;
  132. $fedex_data['cod_ground_return_label'] = 'uploads/fedex/cod_ground_return_label/'.$codlable_file_name;
  133.  
  134. $fedex_data['ursa_code'] = $tracking['ursa_code'];
  135. $fedex_data['service_area'] = $tracking['service_area'];
  136. $fedex_data['state_code'] = $tracking['state_code'];
  137. $fedex_data['postal_code'] = $tracking['postal_code'];
  138. $fedex_data['country_code'] = $tracking['country_code'];
  139. $fedex_data['airport_id'] = $tracking['airport_id'];
  140.  
  141. FedexAwb::model()->addFedexAwb($fedex_data);
  142. } else {
  143. $shipment->courier_id = 0;
  144. $shipment->save();
  145. }
  146. }
Add Comment
Please, Sign In to add comment