Merge branch 'master' into order-delivery-flow
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Procurement order is sent from admin /broker to product suppliers
|
||||
*
|
||||
* For now this system only needs to collect info for admin to generate this order in his own system
|
||||
*
|
||||
* Class Wiaas_Procurement_Order
|
||||
*/
|
||||
class Wiaas_Procurement_Order {
|
||||
|
||||
public static function init() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static function export_procurement_order($order_id) {
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$objPHPExcel = new PHPExcel();
|
||||
|
||||
$customer_user_id = $order->get_customer_id();
|
||||
$organization_id = wiaas_get_user_organization_id($customer_user_id);
|
||||
$customer_organization_info = wiaas_get_organization_info($organization_id);
|
||||
|
||||
$info = array(
|
||||
'number' => $order->get_order_number(),
|
||||
'project_number' => 'SE' . $order->get_order_number(),
|
||||
'reference' => $order->get_meta('_wiaas_reference'),
|
||||
|
||||
'vat_code' => ! empty($customer_organization_info) ? $customer_organization_info['vat_code'] : '',
|
||||
'customer_name' => ! empty($customer_organization_info) ? $customer_organization_info['name'] : '',
|
||||
|
||||
'delivery_address' => $order->get_shipping_address_1() . ',' .
|
||||
$order->get_shipping_city() . ',' .
|
||||
$order->get_shipping_country() . ',' .
|
||||
$order->get_shipping_postcode(),
|
||||
'delivery_full_name' => $order->get_formatted_shipping_full_name(),
|
||||
|
||||
'billing_address' => $order->get_billing_address_1() . ',' .
|
||||
$order->get_billing_city() . ',' .
|
||||
$order->get_billing_country() . ',' .
|
||||
$order->get_billing_postcode(),
|
||||
'billing_full_name' => $order->get_formatted_billing_full_name(),
|
||||
'billing_email' => $order->get_billing_email()
|
||||
);
|
||||
|
||||
$objPHPExcel->getProperties()->setCreator("RICOH")
|
||||
->setLastModifiedBy("Ricoh Dash")
|
||||
->setTitle("Order Procurement Report")
|
||||
->setSubject("Order Procurement Report")
|
||||
->setDescription("Order Procurement Report")
|
||||
->setKeywords("office 2007 openxml php order procurement")
|
||||
->setCategory("Procurement report file");
|
||||
|
||||
|
||||
$objPHPExcel->setActiveSheetIndex(0)
|
||||
->setCellValue('A1', 'Customer details')
|
||||
|
||||
->setCellValue('A2', 'Name')
|
||||
->setCellValue('A3', 'Invoice address')
|
||||
->setCellValue('A4', 'Invoice full name')
|
||||
->setCellValue('A5', 'Invoice email')
|
||||
->setCellValue('A6', 'VAT Number')
|
||||
|
||||
->setCellValue('B2', $info['customer_name'])
|
||||
->setCellValue('B3', $info['billing_address'])
|
||||
->setCellValue('B4', $info['billing_full_name'])
|
||||
->setCellValue('B5', $info['billing_email'])
|
||||
->setCellValue('B6', $info['vat_code']);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
|
||||
|
||||
$objPHPExcel->setActiveSheetIndex(0)
|
||||
->setCellValue('A9', 'OrderDetails')
|
||||
|
||||
->setCellValue('A10', 'Order number')
|
||||
->setCellValue('A11', 'Project number')
|
||||
->setCellValue('A12', 'Delivery address')
|
||||
->setCellValue('A13', 'Delivery full name')
|
||||
->setCellValue('A14', 'Reference')
|
||||
|
||||
->setCellValue('B10', $info['number'])
|
||||
->setCellValue('B11', $info['project_number'])
|
||||
->setCellValue('B12', $info['delivery_address'])
|
||||
->setCellValue('B13', $info['delivery_full_name'])
|
||||
->setCellValue('B14', $info['reference']);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A10')->getFont()->setBold(true);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->setTitle('Order procurement');
|
||||
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
|
||||
header('Content-Disposition: attachment;filename="procurement_report_'.$info['orderNumber'].'.xlsx"');
|
||||
$objWriter->save('php://output');
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Procurement_Order::init();
|
||||
@@ -27,4 +27,88 @@ function wiaas_get_order_standard_bundle_items($order) {
|
||||
}
|
||||
|
||||
return $standard_bundle_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve order summary data for procurement order for suppliers
|
||||
*
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wiaas_get_order_procurement_info($order_id) {
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$order_items = $order->get_items();
|
||||
|
||||
$order_suppliers_info = $order->get_meta('_wiaas_suppliers');
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ($order_items as $order_item_id => $order_item) {
|
||||
|
||||
$category = $order_item['_wiaas_category'];
|
||||
$supplier_organization_id = $order_item['wiaas_supplier_organization_id'];
|
||||
$supplier_info = $order_suppliers_info[$supplier_organization_id];
|
||||
|
||||
if (empty($category)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[$category] ?: array();
|
||||
|
||||
// get price and quantity
|
||||
$single_product_item_cost = floatval($order_item['wiaas_product_price']);
|
||||
|
||||
$quantity = absint($order_item['quantity']);
|
||||
$total_price = $quantity * $single_product_item_cost;
|
||||
|
||||
$data[$category][] = array(
|
||||
'Name' => $order_item->get_name(),
|
||||
'Category' => ucfirst(strtolower($category)),
|
||||
'Manufacturer Product No' => $order_item['wiaas_manufacturer_product_no'],
|
||||
'Supplier Product No' => $order_item['wiaas_supplier_product_no'],
|
||||
'Units' => $quantity,
|
||||
'Price' => $total_price,
|
||||
'Supplier Company' => $supplier_info['name'],
|
||||
'Supplier VAT' => $supplier_info['vat_code'],
|
||||
'Supplier Phone' => $supplier_info['phone'],
|
||||
'Supplier Email' => $supplier_info['email'],
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve delivery supplier organizations for order which does not include installation providers
|
||||
*
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wiaas_get_order_delivery_suppliers($order_id) {
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$supplier_organizations = $order->get_meta('_wiaas_suppliers', true);
|
||||
|
||||
$delivery_supplier_organizations = array();
|
||||
|
||||
$order_items = $order->get_items();
|
||||
|
||||
foreach ($order_items as $order_item_id => $order_item) {
|
||||
|
||||
$supplier_organization_id = $order_item['wiaas_supplier_organization_id'];
|
||||
|
||||
if (! empty($supplier_organization_id) && $order_item['wiaas_category'] !== 'installation' &&
|
||||
empty($delivery_supplier_organizations[$supplier_organization_id])) {
|
||||
|
||||
$delivery_supplier_organizations[$supplier_organization_id] = $supplier_organizations[$supplier_organization_id];
|
||||
}
|
||||
}
|
||||
|
||||
return $delivery_supplier_organizations;
|
||||
}
|
||||
Reference in New Issue
Block a user